pg-to-sqlite 0.5.0 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pg-sqlite-compiler/passes/index.d.ts.map +1 -1
- package/dist/pg-sqlite-compiler/passes/index.js +2 -1
- package/dist/pg-sqlite-compiler/passes/index.js.map +1 -1
- package/dist/pg-sqlite-compiler/passes/json-functions.d.ts +3 -0
- package/dist/pg-sqlite-compiler/passes/json-functions.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/passes/json-functions.js +57 -0
- package/dist/pg-sqlite-compiler/passes/json-functions.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pg-sqlite-compiler/passes/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pg-sqlite-compiler/passes/index.ts"],"names":[],"mappings":"AAUA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEpD,eAAO,MAAM,cAAc,EAAE,IAAI,EAehC,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI,CAc9D"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { catalogPass } from './catalog.js';
|
|
2
2
|
import { datetimePass } from './datetime.js';
|
|
3
3
|
import { dmlCtePass } from './dml-cte.js';
|
|
4
|
+
import { jsonFunctionsPass } from './json-functions.js';
|
|
4
5
|
import { rowJsonPass } from './row-json.js';
|
|
5
6
|
import { schemaPass } from './schema.js';
|
|
6
7
|
import { stringFunctionsPass } from './string-functions.js';
|
|
@@ -12,6 +13,7 @@ export const DEFAULT_PASSES = [
|
|
|
12
13
|
typesPass,
|
|
13
14
|
datetimePass,
|
|
14
15
|
stringFunctionsPass,
|
|
16
|
+
jsonFunctionsPass,
|
|
15
17
|
rowJsonPass,
|
|
16
18
|
catalogPass,
|
|
17
19
|
schemaPass,
|
|
@@ -19,7 +21,6 @@ export const DEFAULT_PASSES = [
|
|
|
19
21
|
// future:
|
|
20
22
|
// castPass,
|
|
21
23
|
// arrayPass,
|
|
22
|
-
// jsonPass,
|
|
23
24
|
// insertPass,
|
|
24
25
|
];
|
|
25
26
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pg-sqlite-compiler/passes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAalD,MAAM,CAAC,MAAM,cAAc,GAAW;IACpC,0EAA0E;IAC1E,UAAU;IACV,SAAS;IACT,YAAY;IACZ,mBAAmB;IACnB,WAAW;IACX,WAAW;IACX,UAAU;IACV,eAAe;IACf,UAAU;IACV,cAAc;IACd,eAAe;IACf,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pg-sqlite-compiler/passes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,iBAAiB,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],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AA+BvC,eAAO,MAAM,iBAAiB,EAAE,IAwB/B,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { walkAst } from './ast-utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* PG's JSON aggregates and constructors have direct SQLite equivalents with
|
|
4
|
+
* the same argument shapes, but different names. Zero's z2s query compiler
|
|
5
|
+
* emits these (json_agg over json_build_object rows is its relationship
|
|
6
|
+
* hydration shape), so passing them through breaks every consumer on real
|
|
7
|
+
* SQLite with "no such function: json_agg".
|
|
8
|
+
*
|
|
9
|
+
* jsonb variants map to the same SQLite functions: SQLite has one JSON text
|
|
10
|
+
* representation, so the jsonb/json distinction erases.
|
|
11
|
+
*/
|
|
12
|
+
const SQLITE_FUNCTION_BY_PG_JSON_FUNCTION = new Map([
|
|
13
|
+
['json_agg', 'json_group_array'],
|
|
14
|
+
['jsonb_agg', 'json_group_array'],
|
|
15
|
+
['json_build_object', 'json_object'],
|
|
16
|
+
['jsonb_build_object', 'json_object'],
|
|
17
|
+
['json_build_array', 'json_array'],
|
|
18
|
+
['jsonb_build_array', 'json_array'],
|
|
19
|
+
['json_object_agg', 'json_group_object'],
|
|
20
|
+
['jsonb_object_agg', 'json_group_object'],
|
|
21
|
+
]);
|
|
22
|
+
function functionName(func) {
|
|
23
|
+
const parts = func?.funcname;
|
|
24
|
+
if (!Array.isArray(parts) || parts.length === 0)
|
|
25
|
+
return null;
|
|
26
|
+
const last = parts[parts.length - 1];
|
|
27
|
+
const value = last?.String?.sval ?? last?.String?.str;
|
|
28
|
+
return typeof value === 'string' ? value.toLowerCase() : null;
|
|
29
|
+
}
|
|
30
|
+
export const jsonFunctionsPass = {
|
|
31
|
+
name: 'json-functions',
|
|
32
|
+
run(rawStmt, ctx) {
|
|
33
|
+
walkAst(rawStmt, {
|
|
34
|
+
FuncCall: (node) => {
|
|
35
|
+
const name = functionName(node);
|
|
36
|
+
if (!name)
|
|
37
|
+
return;
|
|
38
|
+
const replacement = SQLITE_FUNCTION_BY_PG_JSON_FUNCTION.get(name);
|
|
39
|
+
if (!replacement)
|
|
40
|
+
return;
|
|
41
|
+
// SQLite aggregates accept no ORDER BY / FILTER inside the call; a
|
|
42
|
+
// silent rename would change semantics, so surface it instead.
|
|
43
|
+
if (node.agg_order || node.agg_filter) {
|
|
44
|
+
ctx.warnings.push({
|
|
45
|
+
kind: 'unsupported-function',
|
|
46
|
+
near: 'FuncCall',
|
|
47
|
+
message: `${name}() with ORDER BY/FILTER has no SQLite equivalent`,
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
node.funcname = [{ String: { sval: replacement } }];
|
|
52
|
+
node.funcformat = 'COERCE_EXPLICIT_CALL';
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=json-functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-functions.js","sourceRoot":"","sources":["../../../src/pg-sqlite-compiler/passes/json-functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAIxC;;;;;;;;;GASG;AACH,MAAM,mCAAmC,GAAG,IAAI,GAAG,CAAC;IAClD,CAAC,UAAU,EAAE,kBAAkB,CAAC;IAChC,CAAC,WAAW,EAAE,kBAAkB,CAAC;IACjC,CAAC,mBAAmB,EAAE,aAAa,CAAC;IACpC,CAAC,oBAAoB,EAAE,aAAa,CAAC;IACrC,CAAC,kBAAkB,EAAE,YAAY,CAAC;IAClC,CAAC,mBAAmB,EAAE,YAAY,CAAC;IACnC,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;IACxC,CAAC,kBAAkB,EAAE,mBAAmB,CAAC;CAC1C,CAAC,CAAA;AAEF,SAAS,YAAY,CAAC,IAAS;IAC7B,MAAM,KAAK,GAAG,IAAI,EAAE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