@saltcorn/postgres 1.3.1 → 1.4.0-beta.1

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/postgres.js +15 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/postgres",
3
- "version": "1.3.1",
3
+ "version": "1.4.0-beta.1",
4
4
  "description": "Postgres structures for Saltcorn, open-source no-code platform",
5
5
  "homepage": "https://saltcorn.com",
6
6
  "scripts": {
@@ -12,8 +12,8 @@
12
12
  "license": "MIT",
13
13
  "main": "index.js",
14
14
  "dependencies": {
15
- "@saltcorn/db-common": "1.3.1",
16
- "@saltcorn/plain-date": "0.2.0",
15
+ "@saltcorn/db-common": "1.4.0-beta.1",
16
+ "@saltcorn/plain-date": "0.2.5",
17
17
  "pg": "^8.13.1",
18
18
  "pg-copy-streams": "^6.0.6",
19
19
  "replacestream": "4.0.3"
package/postgres.js CHANGED
@@ -281,10 +281,23 @@ const update = async (tbl, obj, id, opts = Object.create(null)) => {
281
281
  let valList = kvs.map(([k, v]) => v);
282
282
  // TBD check that is correct - because in insert function opts.noid ? "*" : opts.pk_name || "id"
283
283
  //valList.push(id === "undefined"? obj[opts.pk_name]: id);
284
- valList.push(id === "undefined" ? obj[opts.pk_name || "id"] : id);
284
+ let whereS;
285
+ if (id && typeof id == "object") {
286
+ let n = kvs.length + 1;
287
+ const whereStrs = [];
288
+ Object.keys(id).forEach((k) => {
289
+ valList.push(id[k]);
290
+ whereStrs.push(`"${k}"=$${n}`);
291
+ n += 1;
292
+ });
293
+ whereS = whereStrs.join(" and ");
294
+ } else {
295
+ valList.push(id === "undefined" ? obj[opts.pk_name || "id"] : id);
296
+ whereS = `${ppPK(opts.pk_name)}=$${kvs.length + 1}`;
297
+ }
285
298
  const q = `update "${opts.schema || getTenantSchema()}"."${sqlsanitize(
286
299
  tbl
287
- )}" set ${assigns} where ${ppPK(opts.pk_name)}=$${kvs.length + 1}`;
300
+ )}" set ${assigns} where ${whereS}`;
288
301
  sql_log(q, valList);
289
302
  await getMyClient(opts).query(q, valList);
290
303
  };