@saltcorn/sql 0.3.6 → 0.3.7

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.6",
3
+ "version": "0.3.7",
4
4
  "description": "Actions and views based on SQL",
5
5
  "main": "index.js",
6
6
  "dependencies": {
package/table-provider.js CHANGED
@@ -182,17 +182,21 @@ const runQuery = async (cfg, where, opts) => {
182
182
  const colNames = new Set((cfg?.columns || []).map((c) => c.name));
183
183
  let phIndex = 1;
184
184
  const phValues = [];
185
+ //console.log(ast[0].columns);
185
186
  for (const k of Object.keys(where)) {
186
187
  if (!colNames.has(k)) continue;
187
- const sqlCol = (ast[0].columns || []).find((c) => k === c.as);
188
+ const sqlCol = (ast[0].columns || []).find(
189
+ (c) => k === c.as || (!c.as && k === c.expr?.column)
190
+ );
188
191
  const sqlExprCol = (ast[0].columns || []).find((c) => c.expr?.as == k);
189
192
  let left = sqlExprCol
190
193
  ? { ...sqlExprCol.expr, as: null }
191
194
  : {
192
195
  type: "column_ref",
193
196
  table: sqlCol?.expr?.table,
194
- column: db.sqlsanitize(k),
197
+ column: sqlCol?.expr?.column || db.sqlsanitize(k),
195
198
  };
199
+ //console.log({ k, sqlCol, sqlExprCol });
196
200
  if (!sqlCol) {
197
201
  const starCol = (ast[0].columns || []).find((c) => c.type === "star_ref");
198
202
  if (starCol)
@@ -243,6 +247,7 @@ const runQuery = async (cfg, where, opts) => {
243
247
  }
244
248
 
245
249
  const sqlQ = parser.sqlify(ast, opt);
250
+ //console.log(sqlQ, phValues);
246
251
  const qres = await client.query(sqlQ, phValues);
247
252
  qres.query = sqlQ;
248
253
  await client.query(`ROLLBACK;`);