From 01cb589ff2ab75e6705b15bc0c0add9707e997e4 Mon Sep 17 00:00:00 2001 From: baqirkhan Date: Fri, 26 Sep 2025 21:31:45 +0530 Subject: [PATCH 1/2] pg: Add test for 'sfWrite' table and handle jsonb null patches in dbWrite tests --- src/pg/test/db/dbWrite.test.js | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/pg/test/db/dbWrite.test.js b/src/pg/test/db/dbWrite.test.js index 0865d22..56c2e52 100644 --- a/src/pg/test/db/dbWrite.test.js +++ b/src/pg/test/db/dbWrite.test.js @@ -90,6 +90,23 @@ describe('postgres', () => { verDefault: 'current_timestamp', }), ); + + store.use( + 'sfWrite', + pg({ + table: 'sfWrite', + idCol: 'id', + verCol: 'updatedAt', + schema: { + types: { + id: 'uuid', + write: 'jsonb', + updatedAt: 'int8', + }, + }, + verDefault: 'current_timestamp', + }), + ); }); afterEach(async () => { @@ -191,4 +208,22 @@ describe('postgres', () => { RETURNING *, "id" AS "$key", current_timestamp AS "$ver"`; expectSql(mockQuery.mock.calls[0][0], sqlQuery); }); + + test('jsonb_null_patch_uses_plain_null', async () => { + await store.write('sfWrite.foo', { + write: { WhatId: { $val: null } }, + }); + + const sqlQuery = sql` + UPDATE "sfWrite" SET + "write" = case jsonb_typeof("write") + when 'object' then "write" + else '{}'::jsonb + end || jsonb_build_object(${'WhatId'}::text, ${'{"WhatId":null}'}::jsonb), + "updatedAt" = default + WHERE "id" = ${'foo'} + RETURNING *, "id" AS "$key", current_timestamp AS "$ver"`; + + expectSql(mockQuery.mock.calls[0][0], sqlQuery); + }); }); From 2aa922d4cec20d75bc2393b47bbd21370b64a104 Mon Sep 17 00:00:00 2001 From: Baqir Khan Date: Fri, 26 Sep 2025 21:45:42 +0530 Subject: [PATCH 2/2] Update src/pg/test/db/dbWrite.test.js Co-authored-by: Aravind Ravi Sulekha --- src/pg/test/db/dbWrite.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pg/test/db/dbWrite.test.js b/src/pg/test/db/dbWrite.test.js index 56c2e52..5e23719 100644 --- a/src/pg/test/db/dbWrite.test.js +++ b/src/pg/test/db/dbWrite.test.js @@ -219,7 +219,7 @@ describe('postgres', () => { "write" = case jsonb_typeof("write") when 'object' then "write" else '{}'::jsonb - end || jsonb_build_object(${'WhatId'}::text, ${'{"WhatId":null}'}::jsonb), + end || jsonb_build_object(${'WhatId'}::text, ${'{"$val":null}'}::jsonb), "updatedAt" = default WHERE "id" = ${'foo'} RETURNING *, "id" AS "$key", current_timestamp AS "$ver"`;