@saltcorn/sql 0.3.2 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/sql",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Actions and views based on SQL",
5
5
  "main": "index.js",
6
6
  "dependencies": {
package/table-provider.js CHANGED
@@ -145,7 +145,7 @@ const sqlEscapeObject = (o) => {
145
145
  return r;
146
146
  };
147
147
 
148
- const runQuery = async (cfg, where) => {
148
+ const runQuery = async (cfg, where, opts) => {
149
149
  const sqlTmpl = cfg?.sql || "";
150
150
  const template = _.template(sqlTmpl || "", {
151
151
  evaluate: /\{\{#(.+?)\}\}/g,
@@ -154,7 +154,9 @@ const runQuery = async (cfg, where) => {
154
154
 
155
155
  const qctx = {};
156
156
 
157
- if (where.forUser) qctx.user = sqlEscapeObject(where.forUser);
157
+ if (opts?.forUser) qctx.user = sqlEscapeObject(opts.forUser);
158
+ else if (where?.forUser)
159
+ qctx.user = sqlEscapeObject(where.forUser); //workaround legacy bug
158
160
  else qctx.user = null;
159
161
 
160
162
  const sql = template(qctx);
@@ -233,8 +235,8 @@ module.exports = {
233
235
  fields: (cfg) => cfg?.columns || [],
234
236
  get_table: (cfg) => {
235
237
  return {
236
- getRows: async (where) => {
237
- const qres = await runQuery(cfg, where);
238
+ getRows: async (where, opts) => {
239
+ const qres = await runQuery(cfg, where, opts);
238
240
  return qres.rows;
239
241
  },
240
242
  };