Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/transform/__fixtures__/input/json-constructors.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- SQL/JSON aggregate constructors carry their own location under a
-- "constructor" key; extra whitespace shifts it on deparse.
SELECT JSON_ARRAYAGG( t.name ORDER BY t.name ) FROM "my-schema".items t;

SELECT JSON_OBJECTAGG( t.id : t.name ) FROM "my-schema".items t;

SELECT JSON_ARRAY( "my-schema".label(1), 2 ), JSON_OBJECT( 'k' : 1 );
11 changes: 11 additions & 0 deletions packages/transform/__fixtures__/output/json-constructors.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- SQL/JSON aggregate constructors carry their own location under a
-- "constructor" key; extra whitespace shifts it on deparse.
SELECT JSON_ARRAYAGG(t.name ORDER BY t.name ABSENT ON NULL)
FROM my_schema.items AS t;

SELECT JSON_OBJECTAGG(t.id : t.name NULL ON NULL)
FROM my_schema.items AS t;

SELECT
JSON_ARRAY(my_schema.label(1), 2 ABSENT ON NULL),
JSON_OBJECT('k' : 1 NULL ON NULL);
3 changes: 2 additions & 1 deletion packages/transform/src/round-trip-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export function normalizeTree(node: any, options: NormalizeTreeOptions = {}): an
const keys = sortKeys ? Object.keys(node).sort() : Object.keys(node);
for (const key of keys) {
if (volatileKeys?.has(key)) continue;
const handler = keyHandlers?.[key];
const handler =
keyHandlers && Object.prototype.hasOwnProperty.call(keyHandlers, key) ? keyHandlers[key] : undefined;
out[key] = handler ? handler(node[key], recurse) : recurse(node[key]);
}
return out;
Expand Down
Loading