@graffy/pg 0.16.20-alpha.8 → 0.16.20
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 +40 -1
- package/index.mjs +40 -1
- package/package.json +3 -3
- package/types/Db.d.ts +2 -2
package/index.cjs
CHANGED
|
@@ -116,6 +116,33 @@ const aggSql = {
|
|
|
116
116
|
$max: (prop) => sql`max((${lookupNumeric(prop)})::numeric)`,
|
|
117
117
|
$min: (prop) => sql`min((${lookupNumeric(prop)})::numeric)`
|
|
118
118
|
};
|
|
119
|
+
const getOptimisedJsonBuild = (object, path, parentPropertyName, options) => {
|
|
120
|
+
const propertyNames = Object.keys(object);
|
|
121
|
+
const propertyPath = [...path, parentPropertyName];
|
|
122
|
+
const buildConfig = [];
|
|
123
|
+
path = path || [];
|
|
124
|
+
propertyNames.forEach((propertyName) => {
|
|
125
|
+
const property = object[propertyName];
|
|
126
|
+
if (typeof property === "object") {
|
|
127
|
+
const childJSONBuild = getOptimisedJsonBuild(
|
|
128
|
+
property,
|
|
129
|
+
propertyPath,
|
|
130
|
+
propertyName,
|
|
131
|
+
options
|
|
132
|
+
);
|
|
133
|
+
buildConfig.push(
|
|
134
|
+
sql`${propertyName}::text, jsonb_build_object(${join(childJSONBuild, ", ")})`
|
|
135
|
+
);
|
|
136
|
+
} else {
|
|
137
|
+
if (property === true) {
|
|
138
|
+
buildConfig.push(
|
|
139
|
+
sql`${propertyName}::text, ${lookup([...propertyPath, propertyName].join("."), options)}`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return buildConfig;
|
|
145
|
+
};
|
|
119
146
|
const getSelectCols = (options, projection = null) => {
|
|
120
147
|
if (!projection) return sql`*`;
|
|
121
148
|
const sqls = [];
|
|
@@ -131,7 +158,19 @@ const getSelectCols = (options, projection = null) => {
|
|
|
131
158
|
sql`jsonb_build_object(${join(subSqls, ", ")}) AS "${raw(key)}"`
|
|
132
159
|
);
|
|
133
160
|
} else {
|
|
134
|
-
|
|
161
|
+
if (typeof projection[key] === "object") {
|
|
162
|
+
const optimisedJsonBuild = getOptimisedJsonBuild(
|
|
163
|
+
projection[key],
|
|
164
|
+
[],
|
|
165
|
+
key,
|
|
166
|
+
options
|
|
167
|
+
);
|
|
168
|
+
sqls.push(
|
|
169
|
+
sql`jsonb_build_object(${join(optimisedJsonBuild, ", ")}) AS "${raw(key)}"`
|
|
170
|
+
);
|
|
171
|
+
} else {
|
|
172
|
+
sqls.push(sql`"${raw(key)}"`);
|
|
173
|
+
}
|
|
135
174
|
}
|
|
136
175
|
}
|
|
137
176
|
return join(sqls, ", ");
|
package/index.mjs
CHANGED
|
@@ -114,6 +114,33 @@ const aggSql = {
|
|
|
114
114
|
$max: (prop) => sql`max((${lookupNumeric(prop)})::numeric)`,
|
|
115
115
|
$min: (prop) => sql`min((${lookupNumeric(prop)})::numeric)`
|
|
116
116
|
};
|
|
117
|
+
const getOptimisedJsonBuild = (object, path, parentPropertyName, options) => {
|
|
118
|
+
const propertyNames = Object.keys(object);
|
|
119
|
+
const propertyPath = [...path, parentPropertyName];
|
|
120
|
+
const buildConfig = [];
|
|
121
|
+
path = path || [];
|
|
122
|
+
propertyNames.forEach((propertyName) => {
|
|
123
|
+
const property = object[propertyName];
|
|
124
|
+
if (typeof property === "object") {
|
|
125
|
+
const childJSONBuild = getOptimisedJsonBuild(
|
|
126
|
+
property,
|
|
127
|
+
propertyPath,
|
|
128
|
+
propertyName,
|
|
129
|
+
options
|
|
130
|
+
);
|
|
131
|
+
buildConfig.push(
|
|
132
|
+
sql`${propertyName}::text, jsonb_build_object(${join(childJSONBuild, ", ")})`
|
|
133
|
+
);
|
|
134
|
+
} else {
|
|
135
|
+
if (property === true) {
|
|
136
|
+
buildConfig.push(
|
|
137
|
+
sql`${propertyName}::text, ${lookup([...propertyPath, propertyName].join("."), options)}`
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return buildConfig;
|
|
143
|
+
};
|
|
117
144
|
const getSelectCols = (options, projection = null) => {
|
|
118
145
|
if (!projection) return sql`*`;
|
|
119
146
|
const sqls = [];
|
|
@@ -129,7 +156,19 @@ const getSelectCols = (options, projection = null) => {
|
|
|
129
156
|
sql`jsonb_build_object(${join(subSqls, ", ")}) AS "${raw(key)}"`
|
|
130
157
|
);
|
|
131
158
|
} else {
|
|
132
|
-
|
|
159
|
+
if (typeof projection[key] === "object") {
|
|
160
|
+
const optimisedJsonBuild = getOptimisedJsonBuild(
|
|
161
|
+
projection[key],
|
|
162
|
+
[],
|
|
163
|
+
key,
|
|
164
|
+
options
|
|
165
|
+
);
|
|
166
|
+
sqls.push(
|
|
167
|
+
sql`jsonb_build_object(${join(optimisedJsonBuild, ", ")}) AS "${raw(key)}"`
|
|
168
|
+
);
|
|
169
|
+
} else {
|
|
170
|
+
sqls.push(sql`"${raw(key)}"`);
|
|
171
|
+
}
|
|
133
172
|
}
|
|
134
173
|
}
|
|
135
174
|
return join(sqls, ", ");
|
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.20
|
|
5
|
+
"version": "0.16.20",
|
|
6
6
|
"main": "./index.cjs",
|
|
7
7
|
"exports": {
|
|
8
8
|
"import": "./index.mjs",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"license": "Apache-2.0",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@graffy/common": "0.16.20
|
|
20
|
-
"debug": "^4.3.
|
|
19
|
+
"@graffy/common": "0.16.20",
|
|
20
|
+
"debug": "^4.3.3"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"pg": "^8.0.0"
|
package/types/Db.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ export default class Db {
|
|
|
6
6
|
writeSql(sql: any, tableOptions: any): Promise<any>;
|
|
7
7
|
ensureSchema(tableOptions: any, typeOids: any): Promise<void>;
|
|
8
8
|
read(rootQuery: any, tableOptions: any): Promise<{
|
|
9
|
-
key: Uint8Array
|
|
10
|
-
end: Uint8Array
|
|
9
|
+
key: Uint8Array<ArrayBuffer>;
|
|
10
|
+
end: Uint8Array<ArrayBuffer>;
|
|
11
11
|
version: number;
|
|
12
12
|
}[]>;
|
|
13
13
|
write(rootChange: any, tableOptions: any): Promise<any[]>;
|