Skip to content

Commit

Permalink
Handle undefined as though its a null when serializing (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
samwillis authored Apr 22, 2024
1 parent da3bddb commit 4e8fbf4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/pglite/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export function serializerFor(x: any): Serializer {
}

export function serializeType(x: any): [string | null, number] {
if (x === null) {
if (x === null || x === undefined) {
return [null, 0];
}
return serializerFor(x)(x);
Expand Down
20 changes: 17 additions & 3 deletions packages/pglite/tests/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ test("basic types", async (t) => {
blob BYTEA,
array_text TEXT[],
array_number INT[],
nested_array_float FLOAT[][]
nested_array_float FLOAT[][],
test_null INT,
test_undefined INT
);
`);

await db.query(
`
INSERT INTO test (text, number, float, bigint, bool, date, timestamp, json, blob, array_text, array_number, nested_array_float)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);
INSERT INTO test (text, number, float, bigint, bool, date, timestamp, json, blob, array_text, array_number, nested_array_float, test_null, test_undefined)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14);
`,
[
"test",
Expand All @@ -112,6 +114,8 @@ test("basic types", async (t) => {
["test1", "test2", "test,3"],
[1, 2, 3],
[[1.1, 2.2], [3.3, 4.4]],
null,
undefined
]
);

Expand All @@ -134,6 +138,8 @@ test("basic types", async (t) => {
array_text: ["test1", "test2", "test,3"],
array_number: [1, 2, 3],
nested_array_float: [[1.1, 2.2], [3.3, 4.4]],
test_null: null,
test_undefined: null,
},
],
fields: [
Expand Down Expand Up @@ -189,6 +195,14 @@ test("basic types", async (t) => {
name: "nested_array_float",
dataTypeID: 1022,
},
{
name: "test_null",
dataTypeID: 23,
},
{
name: "test_undefined",
dataTypeID: 23,
},
],
affectedRows: 0,
});
Expand Down

0 comments on commit 4e8fbf4

Please sign in to comment.