sql-tools 0.1.0 → 0.1.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/bin/sql-tools.js +13 -6
- package/package.json +9 -7
package/bin/sql-tools.js
CHANGED
|
@@ -36,6 +36,11 @@ SqlTools.places={
|
|
|
36
36
|
|
|
37
37
|
SqlTools.olap={};
|
|
38
38
|
|
|
39
|
+
/** @param {string[]} elements */
|
|
40
|
+
function join1wp(elements){
|
|
41
|
+
return (elements.length!=1?'(':'') + elements.join(', ') + (elements.length!=1?')':'');
|
|
42
|
+
}
|
|
43
|
+
|
|
39
44
|
function coalesce(){
|
|
40
45
|
var i=0;
|
|
41
46
|
while(i<arguments.length-1 && arguments[i]==null) i++;
|
|
@@ -172,7 +177,7 @@ SqlTools.structuredData.sqlsDeletes = function sqlsDeletes(data, structuredData,
|
|
|
172
177
|
queriesArray.push(
|
|
173
178
|
"delete from " + SqlTools.quoteIdent(childTable.tableName) +
|
|
174
179
|
" where " + conditionChild.join(' and ') +
|
|
175
|
-
" and " + (parentPk
|
|
180
|
+
" and " + join1wp(parentPk) + `
|
|
176
181
|
not in (select ${parentPk.join(', ')} from jsonb_populate_recordset(null::${SqlTools.quoteIdent(childTable.tableName)},
|
|
177
182
|
${SqlTools.quoteLiteral(JSON.stringify(data[childTable.tableName]))}::jsonb
|
|
178
183
|
));`
|
|
@@ -231,12 +236,14 @@ SqlTools.structuredData.sqlsUpserts = function sqlsUpserts(data, structureData,
|
|
|
231
236
|
for(var i in pkFields){
|
|
232
237
|
where_expr.push(SqlTools.quoteIdent(structureData.tableName) + '.' + SqlTools.quoteIdent(pkFields[i]) + '=' + SqlTools.quoteLiteral(pkValues[i]));
|
|
233
238
|
}
|
|
239
|
+
var doUpdate = ()=>`do update set ( ${SqlTools.quoteIdentArray(fieldsWithoutPk).join(',')} ) =
|
|
240
|
+
${fieldsWithoutPk.length == 1?'row':''} ( ${SqlTools.quoteLiteralArray(valuesWithoutPk).join(',')} )
|
|
241
|
+
where ${where_expr.join(' and ')}`
|
|
234
242
|
var query = `
|
|
235
|
-
insert into
|
|
236
|
-
values (
|
|
237
|
-
on conflict (
|
|
238
|
-
|
|
239
|
-
where ` + where_expr.join(' and ') + `;`
|
|
243
|
+
insert into ${SqlTools.quoteIdent(structureData.tableName)} ( ${fields.join(',')} )
|
|
244
|
+
values ( ${SqlTools.quoteLiteralArray(values).join(',')} )
|
|
245
|
+
on conflict ( ${SqlTools.quoteIdentArray(pkFields).join(',')} )
|
|
246
|
+
${(fieldsWithoutPk.length == 0)?' do nothing':doUpdate()} ;`
|
|
240
247
|
childQueries.unshift(query);
|
|
241
248
|
return childQueries;
|
|
242
249
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sql-tools",
|
|
3
3
|
"description": "olap for sql non-olap engines / and other tools",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.3",
|
|
5
5
|
"author": "Codenautas <codenautas@googlegroups.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "codenautas/sql-tools",
|
|
@@ -12,21 +12,23 @@
|
|
|
12
12
|
}
|
|
13
13
|
],
|
|
14
14
|
"main": "bin/sql-tools.js",
|
|
15
|
-
"dependencies": {
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"type-store": "^0.4.5"
|
|
17
|
+
},
|
|
16
18
|
"devDependencies": {
|
|
17
19
|
"expect.js": "~0.3.1",
|
|
18
20
|
"istanbul": "~0.4.5",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"pg-promise-strict": "~1.
|
|
21
|
+
"mini-tools": "~1.13.4",
|
|
22
|
+
"mocha": "~11.7.5",
|
|
23
|
+
"pg-promise-strict": "~1.4.3"
|
|
22
24
|
},
|
|
23
25
|
"engines": {
|
|
24
26
|
"node": ">= 0.8.0"
|
|
25
27
|
},
|
|
26
28
|
"scripts": {
|
|
27
29
|
"test": "mocha --reporter spec --bail --check-leaks --globals json4allRegisteredTypes test/",
|
|
28
|
-
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",
|
|
29
|
-
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
|
|
30
|
+
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks --globals json4allRegisteredTypes test/",
|
|
31
|
+
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks --globals json4allRegisteredTypes test/",
|
|
30
32
|
"start": "node example/server.js"
|
|
31
33
|
},
|
|
32
34
|
"files": [
|