@graffy/pg 0.16.15-alpha.1 → 0.16.15-alpha.2
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/index.cjs +32 -12
- package/index.mjs +32 -12
- package/package.json +2 -2
- package/types/Db.d.ts +5 -1
- package/types/sql/clauses.d.ts +1 -1
package/index.cjs
CHANGED
|
@@ -34,17 +34,29 @@ class Sql {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
get text() {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const len = this.strings.length;
|
|
38
|
+
let i = 1;
|
|
39
|
+
let value = this.strings[0];
|
|
40
|
+
while (i < len)
|
|
39
41
|
value += `$${i}${this.strings[i++]}`;
|
|
40
42
|
return value;
|
|
41
43
|
}
|
|
42
44
|
get sql() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
const len = this.strings.length;
|
|
46
|
+
let i = 1;
|
|
47
|
+
let value = this.strings[0];
|
|
48
|
+
while (i < len)
|
|
45
49
|
value += `?${this.strings[i++]}`;
|
|
46
50
|
return value;
|
|
47
51
|
}
|
|
52
|
+
get statement() {
|
|
53
|
+
const len = this.strings.length;
|
|
54
|
+
let i = 1;
|
|
55
|
+
let value = this.strings[0];
|
|
56
|
+
while (i < len)
|
|
57
|
+
value += `:${i}${this.strings[i++]}`;
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
48
60
|
inspect() {
|
|
49
61
|
return {
|
|
50
62
|
text: this.text,
|
|
@@ -90,7 +102,7 @@ const lookup = (prop, options) => {
|
|
|
90
102
|
return sql`"${raw(prefix)}" #> ${suffix}`;
|
|
91
103
|
}
|
|
92
104
|
if (types2[prefix] === "cube" && suffix.length === 1) {
|
|
93
|
-
return sql`"${raw(prefix)}" ~> ${parseInt(suffix[0])}`;
|
|
105
|
+
return sql`"${raw(prefix)}" ~> ${Number.parseInt(suffix[0])}`;
|
|
94
106
|
}
|
|
95
107
|
throw Error(`pg.cannot_lookup ${prop}`);
|
|
96
108
|
};
|
|
@@ -207,12 +219,14 @@ const getUpdates = (row, options) => {
|
|
|
207
219
|
);
|
|
208
220
|
};
|
|
209
221
|
function getJsonUpdate(object, col, path) {
|
|
210
|
-
if (!object || typeof object !== "object" || Array.isArray(object) || object.$put
|
|
211
|
-
|
|
212
|
-
if (object == null ? void 0 : object.$val)
|
|
213
|
-
patch2 = { $val: patch2 };
|
|
222
|
+
if (!object || typeof object !== "object" || Array.isArray(object) || object.$put) {
|
|
223
|
+
const patch2 = stripAttributes(object);
|
|
214
224
|
return [sql`${JSON.stringify(patch2)}::jsonb`, patch2 === null];
|
|
215
225
|
}
|
|
226
|
+
if ("$val" in object) {
|
|
227
|
+
const value = object.$val === true ? stripAttributes(object) : object.$val;
|
|
228
|
+
return [sql`${JSON.stringify({ $val: value })}::jsonb`, false];
|
|
229
|
+
}
|
|
216
230
|
const curr = sql`"${raw(col)}"${path.length ? sql`#>${path}` : empty}`;
|
|
217
231
|
if (common.isEmpty(object))
|
|
218
232
|
return [curr, false];
|
|
@@ -401,6 +415,7 @@ function simplify(node) {
|
|
|
401
415
|
}
|
|
402
416
|
const opSql = {
|
|
403
417
|
$and: "AND",
|
|
418
|
+
// Not SQL as these are used as delimiters
|
|
404
419
|
$or: "OR",
|
|
405
420
|
$not: sql`NOT`,
|
|
406
421
|
$eq: sql`=`,
|
|
@@ -690,17 +705,17 @@ class Db {
|
|
|
690
705
|
async query(sql2, tableOptions) {
|
|
691
706
|
var _a, _b;
|
|
692
707
|
log(`Making SQL query: ${sql2.text}`, sql2.values);
|
|
693
|
-
const cubeOid = parseInt(((_b = (_a = tableOptions == null ? void 0 : tableOptions.schema) == null ? void 0 : _a.typeOids) == null ? void 0 : _b.cube) || "0") || null;
|
|
708
|
+
const cubeOid = Number.parseInt(((_b = (_a = tableOptions == null ? void 0 : tableOptions.schema) == null ? void 0 : _a.typeOids) == null ? void 0 : _b.cube) || "0") || null;
|
|
694
709
|
try {
|
|
695
710
|
sql2.types = {
|
|
696
711
|
getTypeParser: (oid, format) => {
|
|
697
712
|
if (oid === types.builtins.INT8) {
|
|
698
|
-
return (value) => parseInt(value, 10);
|
|
713
|
+
return (value) => Number.parseInt(value, 10);
|
|
699
714
|
}
|
|
700
715
|
if (oid === cubeOid) {
|
|
701
716
|
return (value) => {
|
|
702
717
|
const array = value.slice(1, -1).split(/\)\s*,\s*\(/).map(
|
|
703
|
-
(corner) => corner.split(",").map((coord) => parseFloat(coord.trim()))
|
|
718
|
+
(corner) => corner.split(",").map((coord) => Number.parseFloat(coord.trim()))
|
|
704
719
|
);
|
|
705
720
|
return array.length > 1 ? array : array[0];
|
|
706
721
|
};
|
|
@@ -734,6 +749,11 @@ class Db {
|
|
|
734
749
|
}
|
|
735
750
|
return res.rows;
|
|
736
751
|
}
|
|
752
|
+
/*
|
|
753
|
+
Adds .schema to tableOptions if it doesn't exist yet.
|
|
754
|
+
It mutates the argument, to "persist" the results and
|
|
755
|
+
avoid this query in every operation.
|
|
756
|
+
*/
|
|
737
757
|
async ensureSchema(tableOptions, typeOids) {
|
|
738
758
|
if (tableOptions.schema)
|
|
739
759
|
return;
|
package/index.mjs
CHANGED
|
@@ -32,17 +32,29 @@ class Sql {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
get text() {
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
const len = this.strings.length;
|
|
36
|
+
let i = 1;
|
|
37
|
+
let value = this.strings[0];
|
|
38
|
+
while (i < len)
|
|
37
39
|
value += `$${i}${this.strings[i++]}`;
|
|
38
40
|
return value;
|
|
39
41
|
}
|
|
40
42
|
get sql() {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
const len = this.strings.length;
|
|
44
|
+
let i = 1;
|
|
45
|
+
let value = this.strings[0];
|
|
46
|
+
while (i < len)
|
|
43
47
|
value += `?${this.strings[i++]}`;
|
|
44
48
|
return value;
|
|
45
49
|
}
|
|
50
|
+
get statement() {
|
|
51
|
+
const len = this.strings.length;
|
|
52
|
+
let i = 1;
|
|
53
|
+
let value = this.strings[0];
|
|
54
|
+
while (i < len)
|
|
55
|
+
value += `:${i}${this.strings[i++]}`;
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
46
58
|
inspect() {
|
|
47
59
|
return {
|
|
48
60
|
text: this.text,
|
|
@@ -88,7 +100,7 @@ const lookup = (prop, options) => {
|
|
|
88
100
|
return sql`"${raw(prefix)}" #> ${suffix}`;
|
|
89
101
|
}
|
|
90
102
|
if (types2[prefix] === "cube" && suffix.length === 1) {
|
|
91
|
-
return sql`"${raw(prefix)}" ~> ${parseInt(suffix[0])}`;
|
|
103
|
+
return sql`"${raw(prefix)}" ~> ${Number.parseInt(suffix[0])}`;
|
|
92
104
|
}
|
|
93
105
|
throw Error(`pg.cannot_lookup ${prop}`);
|
|
94
106
|
};
|
|
@@ -205,12 +217,14 @@ const getUpdates = (row, options) => {
|
|
|
205
217
|
);
|
|
206
218
|
};
|
|
207
219
|
function getJsonUpdate(object, col, path) {
|
|
208
|
-
if (!object || typeof object !== "object" || Array.isArray(object) || object.$put
|
|
209
|
-
|
|
210
|
-
if (object == null ? void 0 : object.$val)
|
|
211
|
-
patch2 = { $val: patch2 };
|
|
220
|
+
if (!object || typeof object !== "object" || Array.isArray(object) || object.$put) {
|
|
221
|
+
const patch2 = stripAttributes(object);
|
|
212
222
|
return [sql`${JSON.stringify(patch2)}::jsonb`, patch2 === null];
|
|
213
223
|
}
|
|
224
|
+
if ("$val" in object) {
|
|
225
|
+
const value = object.$val === true ? stripAttributes(object) : object.$val;
|
|
226
|
+
return [sql`${JSON.stringify({ $val: value })}::jsonb`, false];
|
|
227
|
+
}
|
|
214
228
|
const curr = sql`"${raw(col)}"${path.length ? sql`#>${path}` : empty}`;
|
|
215
229
|
if (isEmpty(object))
|
|
216
230
|
return [curr, false];
|
|
@@ -399,6 +413,7 @@ function simplify(node) {
|
|
|
399
413
|
}
|
|
400
414
|
const opSql = {
|
|
401
415
|
$and: "AND",
|
|
416
|
+
// Not SQL as these are used as delimiters
|
|
402
417
|
$or: "OR",
|
|
403
418
|
$not: sql`NOT`,
|
|
404
419
|
$eq: sql`=`,
|
|
@@ -688,17 +703,17 @@ class Db {
|
|
|
688
703
|
async query(sql2, tableOptions) {
|
|
689
704
|
var _a, _b;
|
|
690
705
|
log(`Making SQL query: ${sql2.text}`, sql2.values);
|
|
691
|
-
const cubeOid = parseInt(((_b = (_a = tableOptions == null ? void 0 : tableOptions.schema) == null ? void 0 : _a.typeOids) == null ? void 0 : _b.cube) || "0") || null;
|
|
706
|
+
const cubeOid = Number.parseInt(((_b = (_a = tableOptions == null ? void 0 : tableOptions.schema) == null ? void 0 : _a.typeOids) == null ? void 0 : _b.cube) || "0") || null;
|
|
692
707
|
try {
|
|
693
708
|
sql2.types = {
|
|
694
709
|
getTypeParser: (oid, format) => {
|
|
695
710
|
if (oid === types.builtins.INT8) {
|
|
696
|
-
return (value) => parseInt(value, 10);
|
|
711
|
+
return (value) => Number.parseInt(value, 10);
|
|
697
712
|
}
|
|
698
713
|
if (oid === cubeOid) {
|
|
699
714
|
return (value) => {
|
|
700
715
|
const array = value.slice(1, -1).split(/\)\s*,\s*\(/).map(
|
|
701
|
-
(corner) => corner.split(",").map((coord) => parseFloat(coord.trim()))
|
|
716
|
+
(corner) => corner.split(",").map((coord) => Number.parseFloat(coord.trim()))
|
|
702
717
|
);
|
|
703
718
|
return array.length > 1 ? array : array[0];
|
|
704
719
|
};
|
|
@@ -732,6 +747,11 @@ class Db {
|
|
|
732
747
|
}
|
|
733
748
|
return res.rows;
|
|
734
749
|
}
|
|
750
|
+
/*
|
|
751
|
+
Adds .schema to tableOptions if it doesn't exist yet.
|
|
752
|
+
It mutates the argument, to "persist" the results and
|
|
753
|
+
avoid this query in every operation.
|
|
754
|
+
*/
|
|
735
755
|
async ensureSchema(tableOptions, typeOids) {
|
|
736
756
|
if (tableOptions.schema)
|
|
737
757
|
return;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graffy/pg",
|
|
3
3
|
"description": "The standard Postgres module for Graffy. Each instance this module mounts a Postgres table as a Graffy subtree.",
|
|
4
4
|
"author": "aravind (https://github.com/aravindet)",
|
|
5
|
-
"version": "0.16.15-alpha.
|
|
5
|
+
"version": "0.16.15-alpha.2",
|
|
6
6
|
"main": "./index.cjs",
|
|
7
7
|
"exports": {
|
|
8
8
|
"import": "./index.mjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"license": "Apache-2.0",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@graffy/common": "0.16.15-alpha.
|
|
19
|
+
"@graffy/common": "0.16.15-alpha.2",
|
|
20
20
|
"debug": "^4.3.3"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
package/types/Db.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ export default class Db {
|
|
|
5
5
|
readSql(sql: any, tableOptions: any): Promise<any>;
|
|
6
6
|
writeSql(sql: any, tableOptions: any): Promise<any>;
|
|
7
7
|
ensureSchema(tableOptions: any, typeOids: any): Promise<void>;
|
|
8
|
-
read(rootQuery: any, tableOptions: any): Promise<
|
|
8
|
+
read(rootQuery: any, tableOptions: any): Promise<{
|
|
9
|
+
key: Uint8Array;
|
|
10
|
+
end: Uint8Array;
|
|
11
|
+
version: number;
|
|
12
|
+
}[]>;
|
|
9
13
|
write(rootChange: any, tableOptions: any): Promise<any[]>;
|
|
10
14
|
}
|
package/types/sql/clauses.d.ts
CHANGED