@graffy/pg 0.15.10-alpha.1 → 0.15.10-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 +6 -6
- package/index.mjs +7 -7
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -269,7 +269,7 @@ const getJsonBuildValue = (value) => {
|
|
|
269
269
|
return value;
|
|
270
270
|
if (typeof value === "string")
|
|
271
271
|
return sql__default["default"]`${value}::text`;
|
|
272
|
-
return sql__default["default"]`${stripAttributes(value)}::jsonb`;
|
|
272
|
+
return sql__default["default"]`${JSON.stringify(stripAttributes(value))}::jsonb`;
|
|
273
273
|
};
|
|
274
274
|
const getSelectCols = (table) => {
|
|
275
275
|
return sql__default["default"]`to_jsonb("${sql.raw(table)}")`;
|
|
@@ -279,13 +279,13 @@ const getInsert = (row, options) => {
|
|
|
279
279
|
const vals = [];
|
|
280
280
|
Object.entries(row).filter(([name]) => name !== options.verCol && name[0] !== "$").concat([[options.verCol, nowTimestamp]]).forEach(([col, val]) => {
|
|
281
281
|
cols.push(sql__default["default"]`"${sql.raw(col)}"`);
|
|
282
|
-
vals.push(val instanceof sql.Sql ? val : stripAttributes(val));
|
|
282
|
+
vals.push(val instanceof sql.Sql || typeof val !== "object" || !val ? val : sql__default["default"]`${JSON.stringify(stripAttributes(val))}::jsonb`);
|
|
283
283
|
});
|
|
284
284
|
return { cols: sql.join(cols, ", "), vals: sql.join(vals, ", ") };
|
|
285
285
|
};
|
|
286
286
|
const getUpdates = (row, options) => {
|
|
287
287
|
return sql.join(Object.entries(row).filter(([name]) => name !== options.idCol && name[0] !== "$").map(([name, value]) => {
|
|
288
|
-
return sql__default["default"]`"${sql.raw(name)}" = ${typeof value
|
|
288
|
+
return sql__default["default"]`"${sql.raw(name)}" = ${value instanceof sql.Sql || typeof value !== "object" || !value ? value : !value.$put ? sql__default["default"]`jsonb_strip_nulls(${getJsonUpdate(value, name, [])})` : sql__default["default"]`${JSON.stringify(stripAttributes(value))}::jsonb`}`;
|
|
289
289
|
}).concat(sql__default["default"]`"${sql.raw(options.verCol)}" = ${nowTimestamp}`), ", ");
|
|
290
290
|
};
|
|
291
291
|
function getJsonUpdate(_a, col, path) {
|
|
@@ -304,14 +304,14 @@ function stripAttributes(object) {
|
|
|
304
304
|
if (typeof object !== "object" || !object)
|
|
305
305
|
return object;
|
|
306
306
|
if (Array.isArray(object)) {
|
|
307
|
-
return
|
|
307
|
+
return object.map((item) => stripAttributes(item));
|
|
308
308
|
}
|
|
309
|
-
return
|
|
309
|
+
return Object.entries(object).reduce((out, [key, val]) => {
|
|
310
310
|
if (key === "$put")
|
|
311
311
|
return out;
|
|
312
312
|
out[key] = stripAttributes(val);
|
|
313
313
|
return out;
|
|
314
|
-
}, {})
|
|
314
|
+
}, {});
|
|
315
315
|
}
|
|
316
316
|
const getIdMeta = ({ idCol }) => getJsonBuildObject({
|
|
317
317
|
$key: sql__default["default"]`"${sql.raw(idCol)}"`,
|
package/index.mjs
CHANGED
|
@@ -28,7 +28,7 @@ var __objRest = (source, exclude) => {
|
|
|
28
28
|
};
|
|
29
29
|
import { isEmpty, encodePath, isPlainObject, unwrap, decodeArgs, slice, finalize, isRange, decodeGraph, mergeObject, merge, encodeGraph, wrapObject, remove } from "@graffy/common";
|
|
30
30
|
import { Pool, Client } from "pg";
|
|
31
|
-
import sql, { join, raw,
|
|
31
|
+
import sql, { join, raw, Sql, empty } from "sql-template-tag";
|
|
32
32
|
import debug from "debug";
|
|
33
33
|
const valid = {
|
|
34
34
|
$eq: true,
|
|
@@ -261,7 +261,7 @@ const getJsonBuildValue = (value) => {
|
|
|
261
261
|
return value;
|
|
262
262
|
if (typeof value === "string")
|
|
263
263
|
return sql`${value}::text`;
|
|
264
|
-
return sql`${stripAttributes(value)}::jsonb`;
|
|
264
|
+
return sql`${JSON.stringify(stripAttributes(value))}::jsonb`;
|
|
265
265
|
};
|
|
266
266
|
const getSelectCols = (table) => {
|
|
267
267
|
return sql`to_jsonb("${raw(table)}")`;
|
|
@@ -271,13 +271,13 @@ const getInsert = (row, options) => {
|
|
|
271
271
|
const vals = [];
|
|
272
272
|
Object.entries(row).filter(([name]) => name !== options.verCol && name[0] !== "$").concat([[options.verCol, nowTimestamp]]).forEach(([col, val]) => {
|
|
273
273
|
cols.push(sql`"${raw(col)}"`);
|
|
274
|
-
vals.push(val instanceof Sql ? val : stripAttributes(val));
|
|
274
|
+
vals.push(val instanceof Sql || typeof val !== "object" || !val ? val : sql`${JSON.stringify(stripAttributes(val))}::jsonb`);
|
|
275
275
|
});
|
|
276
276
|
return { cols: join(cols, ", "), vals: join(vals, ", ") };
|
|
277
277
|
};
|
|
278
278
|
const getUpdates = (row, options) => {
|
|
279
279
|
return join(Object.entries(row).filter(([name]) => name !== options.idCol && name[0] !== "$").map(([name, value]) => {
|
|
280
|
-
return sql`"${raw(name)}" = ${typeof value
|
|
280
|
+
return sql`"${raw(name)}" = ${value instanceof Sql || typeof value !== "object" || !value ? value : !value.$put ? sql`jsonb_strip_nulls(${getJsonUpdate(value, name, [])})` : sql`${JSON.stringify(stripAttributes(value))}::jsonb`}`;
|
|
281
281
|
}).concat(sql`"${raw(options.verCol)}" = ${nowTimestamp}`), ", ");
|
|
282
282
|
};
|
|
283
283
|
function getJsonUpdate(_a, col, path) {
|
|
@@ -296,14 +296,14 @@ function stripAttributes(object) {
|
|
|
296
296
|
if (typeof object !== "object" || !object)
|
|
297
297
|
return object;
|
|
298
298
|
if (Array.isArray(object)) {
|
|
299
|
-
return
|
|
299
|
+
return object.map((item) => stripAttributes(item));
|
|
300
300
|
}
|
|
301
|
-
return
|
|
301
|
+
return Object.entries(object).reduce((out, [key, val]) => {
|
|
302
302
|
if (key === "$put")
|
|
303
303
|
return out;
|
|
304
304
|
out[key] = stripAttributes(val);
|
|
305
305
|
return out;
|
|
306
|
-
}, {})
|
|
306
|
+
}, {});
|
|
307
307
|
}
|
|
308
308
|
const getIdMeta = ({ idCol }) => getJsonBuildObject({
|
|
309
309
|
$key: sql`"${raw(idCol)}"`,
|
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.15.10-alpha.
|
|
5
|
+
"version": "0.15.10-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.15.10-alpha.
|
|
19
|
+
"@graffy/common": "0.15.10-alpha.2",
|
|
20
20
|
"pg": "^8.7.1",
|
|
21
21
|
"debug": "^4.3.2",
|
|
22
22
|
"sql-template-tag": "^4.0.0"
|