@saltcorn/sql 0.5.6 → 0.5.8
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.js +12 -7
- package/package.json +1 -1
- package/table-provider.js +10 -2
package/index.js
CHANGED
|
@@ -64,7 +64,7 @@ const configuration_workflow = () =>
|
|
|
64
64
|
input_type: "section_header",
|
|
65
65
|
label: " ",
|
|
66
66
|
sublabel: div(
|
|
67
|
-
"Use handlebars to access query result in the <code>rows</code> variable. Example: <code>{{#each rows}}<h1>{{this.name}}</h1>{{/each}}</code>"
|
|
67
|
+
"Use handlebars to access query result in the <code>rows</code> variable. Example: <code>{{#each rows}}<h1>{{this.name}}</h1>{{/each}}</code>",
|
|
68
68
|
),
|
|
69
69
|
showIf: { row_count: "Many" },
|
|
70
70
|
},
|
|
@@ -82,7 +82,7 @@ const run = async (
|
|
|
82
82
|
viewname,
|
|
83
83
|
{ sql, output_type, state_parameters, html_code },
|
|
84
84
|
state,
|
|
85
|
-
{ req }
|
|
85
|
+
{ req },
|
|
86
86
|
) => {
|
|
87
87
|
const is_sqlite = db.isSQLite;
|
|
88
88
|
|
|
@@ -104,7 +104,7 @@ const run = async (
|
|
|
104
104
|
if (!is_sqlite) {
|
|
105
105
|
await client.query(`SET LOCAL search_path TO "${db.getTenantSchema()}";`);
|
|
106
106
|
await client.query(
|
|
107
|
-
`SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY
|
|
107
|
+
`SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;`,
|
|
108
108
|
);
|
|
109
109
|
}
|
|
110
110
|
qres = await client.query(sql, phValues);
|
|
@@ -123,7 +123,7 @@ const run = async (
|
|
|
123
123
|
html_code,
|
|
124
124
|
{ rows: qres.rows },
|
|
125
125
|
req.user,
|
|
126
|
-
`HTML code interpolation in view ${viewname}
|
|
126
|
+
`HTML code interpolation in view ${viewname}`,
|
|
127
127
|
);
|
|
128
128
|
//return template();
|
|
129
129
|
|
|
@@ -133,7 +133,7 @@ const run = async (
|
|
|
133
133
|
default: //Table
|
|
134
134
|
return mkTable(
|
|
135
135
|
qres.fields.map((field) => ({ label: field.name, key: field.name })),
|
|
136
|
-
qres.rows
|
|
136
|
+
qres.rows,
|
|
137
137
|
);
|
|
138
138
|
}
|
|
139
139
|
};
|
|
@@ -157,21 +157,26 @@ module.exports = {
|
|
|
157
157
|
if (!is_sqlite) {
|
|
158
158
|
db.sql_log(`SET LOCAL search_path TO "${db.getTenantSchema()}";`);
|
|
159
159
|
await client.query(
|
|
160
|
-
`SET LOCAL search_path TO "${db.getTenantSchema()}"
|
|
160
|
+
`SET LOCAL search_path TO "${db.getTenantSchema()}";`,
|
|
161
161
|
);
|
|
162
162
|
db.sql_log(`SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;`);
|
|
163
163
|
await client.query(
|
|
164
|
-
`SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY
|
|
164
|
+
`SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;`,
|
|
165
165
|
);
|
|
166
166
|
}
|
|
167
167
|
db.sql_log(query, parameters || []);
|
|
168
168
|
const qres = await client.query(query, parameters || []);
|
|
169
169
|
db.sql_log("ROLLBACK;");
|
|
170
170
|
await client.query(`ROLLBACK;`);
|
|
171
|
+
if (!is_sqlite) client.release();
|
|
171
172
|
return qres;
|
|
172
173
|
},
|
|
173
174
|
isAsync: true,
|
|
174
175
|
description: "Run an SQL query",
|
|
176
|
+
arguments: [
|
|
177
|
+
{ name: "sql_query", type: "String", required: true },
|
|
178
|
+
{ name: "parameters", type: "JSON", tstype: "any[]" },
|
|
179
|
+
],
|
|
175
180
|
},
|
|
176
181
|
},
|
|
177
182
|
viewtemplates: [
|
package/package.json
CHANGED
package/table-provider.js
CHANGED
|
@@ -443,6 +443,8 @@ const countRows = async (cfg, where, opts) => {
|
|
|
443
443
|
});
|
|
444
444
|
|
|
445
445
|
const qctx = {};
|
|
446
|
+
const ensure_no_final_semicolon = (s) =>
|
|
447
|
+
s.trim().endsWith(";") ? s.trim().slice(0, -1) : s;
|
|
446
448
|
|
|
447
449
|
if (opts?.forUser) qctx.user = sqlEscapeObject(opts.forUser);
|
|
448
450
|
else if (where?.forUser)
|
|
@@ -465,8 +467,14 @@ const countRows = async (cfg, where, opts) => {
|
|
|
465
467
|
}
|
|
466
468
|
|
|
467
469
|
//console.trace({ sqlQ, phValues, opts });
|
|
468
|
-
db.sql_log(
|
|
469
|
-
|
|
470
|
+
db.sql_log(
|
|
471
|
+
`select count(*) from (${ensure_no_final_semicolon(sqlQ)})`,
|
|
472
|
+
phValues
|
|
473
|
+
);
|
|
474
|
+
const qres = await client.query(
|
|
475
|
+
`select count(*) from (${ensure_no_final_semicolon(sqlQ)})`,
|
|
476
|
+
phValues
|
|
477
|
+
);
|
|
470
478
|
qres.query = sqlQ;
|
|
471
479
|
db.sql_log("ROLLBACK;");
|
|
472
480
|
await client.query(`ROLLBACK;`);
|