From d4d9199c8f5f0a680f70b446825cfd7a682c8133 Mon Sep 17 00:00:00 2001 From: e3dio <85405955+e3dio@users.noreply.github.com> Date: Mon, 23 May 2022 17:35:32 -0700 Subject: [PATCH 1/3] fix null in array --- src/types.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.js b/src/types.js index 93ddaa29..42e9fb09 100644 --- a/src/types.js +++ b/src/types.js @@ -243,7 +243,7 @@ export const arraySerializer = function arraySerializer(xs, serializer) { if (Array.isArray(first) && !first.type) return '{' + xs.map(x => arraySerializer(x, serializer)).join(',') + '}' - return '{' + xs.map(x => + return '{' + xs.map(x => x === null ? 'null' : '"' + arrayEscape(serializer ? serializer(x.type ? x.value : x) : '' + x) + '"' ).join(',') + '}' } From a8dfa7e98d24767606e6a8eda56ea5b0bf8cd935 Mon Sep 17 00:00:00 2001 From: e3dio <85405955+e3dio@users.noreply.github.com> Date: Mon, 23 May 2022 18:02:20 -0700 Subject: [PATCH 2/3] also map undefined values to null --- src/types.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.js b/src/types.js index 42e9fb09..521b2d95 100644 --- a/src/types.js +++ b/src/types.js @@ -243,7 +243,7 @@ export const arraySerializer = function arraySerializer(xs, serializer) { if (Array.isArray(first) && !first.type) return '{' + xs.map(x => arraySerializer(x, serializer)).join(',') + '}' - return '{' + xs.map(x => x === null ? 'null' : + return '{' + xs.map(x => x == null ? 'null' : '"' + arrayEscape(serializer ? serializer(x.type ? x.value : x) : '' + x) + '"' ).join(',') + '}' } From f2f1a4a5cbaa5e989945ea47b7602c36494de813 Mon Sep 17 00:00:00 2001 From: e3dio <85405955+e3dio@users.noreply.github.com> Date: Mon, 23 May 2022 18:57:55 -0700 Subject: [PATCH 3/3] fix readme typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 36e20a53..a6fb6fcd 100644 --- a/README.md +++ b/README.md @@ -898,7 +898,7 @@ Prepared statements will automatically be created for any queries where it can b ## Custom Types -You can add ergonomic support for custom types, or simply use `sql.typed(value, type)` inline, where type is the PostgreSQL `oid` for the type and the correctly serialized string. _(`oid` values for types can be found in the `pg_catalog.pg_types` table.)_ +You can add ergonomic support for custom types, or simply use `sql.typed(value, type)` inline, where type is the PostgreSQL `oid` for the type and the correctly serialized string. _(`oid` values for types can be found in the `pg_catalog.pg_type` table.)_ Adding Query helpers is the cleanest approach which can be done like this: