Skip to content

Commit a63cbde

Browse files
authored
Fix db saves as false (#444)
* fix: assert write & read equivalence in test * fix: bool type sql conversion
1 parent 4372a74 commit a63cbde

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

codegenerator/cli/npm/envio/src/db/Table.res

+3-2
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ let toSqlParams = (table: table, ~schema) => {
214214
| Bool =>
215215
// Workaround for https://github.com/porsager/postgres/issues/471
216216
S.union([
217-
S.literal("t")->S.to(_ => true),
218-
S.literal("f")->S.to(_ => false),
217+
S.literal(1)->S.to(_ => true),
218+
S.literal(0)->S.to(_ => false),
219219
])->S.toUnknown
220220
| _ => schema
221221
}
@@ -242,6 +242,7 @@ let toSqlParams = (table: table, ~schema) => {
242242
| Field(f) =>
243243
switch f.fieldType {
244244
| Custom(fieldType) => `${(Text :> string)}[]::${(fieldType :> string)}`
245+
| Boolean => `${(Integer :> string)}[]::${(f.fieldType :> string)}`
245246
| fieldType => (fieldType :> string)
246247
}
247248
| DerivedFrom(_) => (Text :> string)

codegenerator/cli/templates/static/codegen/src/db/DbFunctions.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ SELECT * FROM unnest(${arrayFieldTypes
6666
}
6767
} else {
6868
let convertOrThrow = S.compile(
69-
S.array(dbSchema),
69+
S.array(schema),
7070
~input=Value,
7171
~output=Unknown,
7272
~mode=Sync,

scenarios/test_codegen/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
- `pnpm docker-up`
1111

12+
- Make sure to gen ts types in contracts dir `(cd contracts && npx hardhat compile)`
13+
1214
- Then run the tests and confirm all pass:
1315
- `pnpm test`
1416

1517

1618
### Clean up
1719

18-
run `pnpm docker-down`
20+
run `pnpm docker-down`

scenarios/test_codegen/test/SerDe_Test.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe("SerDe Test", () => {
8181
| exception exn =>
8282
Js.log(exn)
8383
Assert.fail("Failed to read entity from table")
84-
| [_entity] => ()
84+
| [_entity] => Assert.deepEqual(_entity, entity)
8585
| _ => Assert.fail("Should have returned a row on batch read fn")
8686
}
8787

@@ -159,7 +159,7 @@ describe("SerDe Test", () => {
159159
| exception exn =>
160160
Js.log(exn)
161161
Assert.fail("Failed to read entity from table")
162-
| [_entity] => ()
162+
| [_entity] => Assert.deepEqual(_entity, entity)
163163
| _ => Assert.fail("Should have returned a row on batch read fn")
164164
}
165165

0 commit comments

Comments
 (0)