@graffy/pg 0.17.6 → 0.17.8-alpha.1
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 +5 -1
- package/index.mjs +5 -1
- package/package.json +2 -2
- package/types/sql/getArgSql.d.ts +4 -1
package/index.cjs
CHANGED
|
@@ -118,9 +118,13 @@ const getJsonBuildValue = (value) => {
|
|
|
118
118
|
if (typeof value === "string") return sql`${value}::text`;
|
|
119
119
|
return sql`${JSON.stringify(stripAttributes(value))}::jsonb`;
|
|
120
120
|
};
|
|
121
|
+
function colName(prefix, options) {
|
|
122
|
+
if (!options.schema.types[prefix]) throw Error(`pg.no_column ${prefix}`);
|
|
123
|
+
return raw(prefix);
|
|
124
|
+
}
|
|
121
125
|
const lookup = (prop, options) => {
|
|
122
126
|
const [prefix, ...suffix] = prop.split(".");
|
|
123
|
-
if (!suffix.length) return sql`"${
|
|
127
|
+
if (!suffix.length) return sql`"${colName(prefix, options)}"`;
|
|
124
128
|
const { types: types2 } = options.schema;
|
|
125
129
|
if (types2[prefix] === "jsonb") {
|
|
126
130
|
return sql`"${raw(prefix)}" #> ${suffix}`;
|
package/index.mjs
CHANGED
|
@@ -116,9 +116,13 @@ const getJsonBuildValue = (value) => {
|
|
|
116
116
|
if (typeof value === "string") return sql`${value}::text`;
|
|
117
117
|
return sql`${JSON.stringify(stripAttributes(value))}::jsonb`;
|
|
118
118
|
};
|
|
119
|
+
function colName(prefix, options) {
|
|
120
|
+
if (!options.schema.types[prefix]) throw Error(`pg.no_column ${prefix}`);
|
|
121
|
+
return raw(prefix);
|
|
122
|
+
}
|
|
119
123
|
const lookup = (prop, options) => {
|
|
120
124
|
const [prefix, ...suffix] = prop.split(".");
|
|
121
|
-
if (!suffix.length) return sql`"${
|
|
125
|
+
if (!suffix.length) return sql`"${colName(prefix, options)}"`;
|
|
122
126
|
const { types: types2 } = options.schema;
|
|
123
127
|
if (types2[prefix] === "jsonb") {
|
|
124
128
|
return sql`"${raw(prefix)}" #> ${suffix}`;
|
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.17.
|
|
5
|
+
"version": "0.17.8-alpha.1",
|
|
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.17.
|
|
19
|
+
"@graffy/common": "0.17.8-alpha.1",
|
|
20
20
|
"debug": "^4.4.1",
|
|
21
21
|
"sql-formatter": "^15.6.4"
|
|
22
22
|
},
|
package/types/sql/getArgSql.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Uses the args object (typically passed in the $key attribute)
|
|
3
3
|
|
|
4
4
|
@param {object} args
|
|
5
|
-
@param {{prefix: string, idCol: string, verDefault: string}} options
|
|
5
|
+
@param {{prefix: string, idCol: string, verDefault: string, schema: { types: Record<string, any> } }} options
|
|
6
6
|
|
|
7
7
|
@typedef { import('sql-template-tag').Sql } Sql
|
|
8
8
|
@return {{ meta: Sql, where: Sql[], order?: Sql, group?: Sql, limit: number, ensureSingleRow: boolean }}
|
|
@@ -11,6 +11,9 @@ export default function getArgSql({ $first, $last, $after, $before, $since, $unt
|
|
|
11
11
|
prefix: string;
|
|
12
12
|
idCol: string;
|
|
13
13
|
verDefault: string;
|
|
14
|
+
schema: {
|
|
15
|
+
types: Record<string, any>;
|
|
16
|
+
};
|
|
14
17
|
}): {
|
|
15
18
|
meta: Sql;
|
|
16
19
|
where: Sql[];
|