@saltcorn/postgres 0.8.6-beta.1 → 0.8.6-beta.10

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 +2 -2
  2. package/postgres.js +7 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/postgres",
3
- "version": "0.8.6-beta.1",
3
+ "version": "0.8.6-beta.10",
4
4
  "description": "Postgres structures for Saltcorn, open-source no-code platform",
5
5
  "homepage": "https://saltcorn.com",
6
6
  "scripts": {
@@ -12,7 +12,7 @@
12
12
  "license": "MIT",
13
13
  "main": "index.js",
14
14
  "dependencies": {
15
- "@saltcorn/db-common": "0.8.6-beta.1",
15
+ "@saltcorn/db-common": "0.8.6-beta.10",
16
16
  "pg": "^8.2.1",
17
17
  "pg-copy-streams": "^5.1.1"
18
18
  },
package/postgres.js CHANGED
@@ -217,7 +217,7 @@ const update = async (tbl, obj, id, opts = {}) => {
217
217
  tbl
218
218
  )}" set ${assigns} where ${opts.pk_name || "id"}=$${kvs.length + 1}`;
219
219
  sql_log(q, valList);
220
- await pool.query(q, valList);
220
+ await (opts.client || pool).query(q, valList);
221
221
  };
222
222
 
223
223
  /**
@@ -225,9 +225,10 @@ const update = async (tbl, obj, id, opts = {}) => {
225
225
  * @param {string} tbl - table name
226
226
  * @param {object} obj - columns names and data
227
227
  * @param {object} whereObj - where object
228
+ * @param {object} opts - can contain a db client for transactions
228
229
  * @returns {Promise<void>} no result
229
230
  */
230
- const updateWhere = async (tbl, obj, whereObj) => {
231
+ const updateWhere = async (tbl, obj, whereObj, opts = {}) => {
231
232
  const kvs = Object.entries(obj);
232
233
  if (kvs.length === 0) return;
233
234
  const { where, values } = mkWhere(whereObj, false, kvs.length);
@@ -240,7 +241,7 @@ const updateWhere = async (tbl, obj, whereObj) => {
240
241
  tbl
241
242
  )}" set ${assigns} ${where}`;
242
243
  sql_log(q, valList);
243
- await pool.query(q, valList);
244
+ await (opts.client || pool).query(q, valList);
244
245
  };
245
246
 
246
247
  /**
@@ -356,9 +357,9 @@ const add_index = async (table_name, field_name) => {
356
357
  */
357
358
  const drop_index = async (table_name, field_name) => {
358
359
  // TBD check that there are no problems with lenght of constraint name
359
- const sql = `drop index "${getTenantSchema()}"."${sqlsanitize(table_name)}_${sqlsanitize(
360
- field_name
361
- )}_index";`;
360
+ const sql = `drop index "${getTenantSchema()}"."${sqlsanitize(
361
+ table_name
362
+ )}_${sqlsanitize(field_name)}_index";`;
362
363
  sql_log(sql);
363
364
  await pool.query(sql);
364
365
  };