@saltcorn/postgres 1.3.1-beta.11 → 1.3.1-beta.12

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 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/postgres",
3
- "version": "1.3.1-beta.11",
3
+ "version": "1.3.1-beta.12",
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": "1.3.1-beta.11",
15
+ "@saltcorn/db-common": "1.3.1-beta.12",
16
16
  "@saltcorn/plain-date": "0.1.4",
17
17
  "pg": "^8.13.1",
18
18
  "pg-copy-streams": "^6.0.6",
package/postgres.js CHANGED
@@ -142,7 +142,7 @@ const drop_reset_schema = async (schema) => {
142
142
  * @param {object} - whereObj - where object
143
143
  * @returns {Promise<number>} count of tables
144
144
  */
145
- const count = async (tbl, whereObj) => {
145
+ const count = async (tbl, whereObj, opts) => {
146
146
  const { where, values } = mkWhere(whereObj);
147
147
  if (!where) {
148
148
  try {
@@ -156,9 +156,9 @@ const count = async (tbl, whereObj) => {
156
156
  / pg_catalog.current_setting('block_size')::int)
157
157
  )::bigint
158
158
  FROM pg_catalog.pg_class c
159
- WHERE c.oid = '"${getTenantSchema()}"."${sqlsanitize(tbl)}"'::regclass`;
159
+ WHERE c.oid = '"${opts?.schema || getTenantSchema()}"."${sqlsanitize(tbl)}"'::regclass`;
160
160
  sql_log(sql);
161
- const tq = await getMyClient().query(sql, []);
161
+ const tq = await getMyClient(opts).query(sql, []);
162
162
  const n = +tq.rows[0].int8;
163
163
  if (n && n > 10000) return n;
164
164
  } catch {
@@ -166,11 +166,11 @@ WHERE c.oid = '"${getTenantSchema()}"."${sqlsanitize(tbl)}"'::regclass`;
166
166
  }
167
167
  }
168
168
 
169
- const sql = `SELECT COUNT(*) FROM "${getTenantSchema()}"."${sqlsanitize(
169
+ const sql = `SELECT COUNT(*) FROM "${opts?.schema || getTenantSchema()}"."${sqlsanitize(
170
170
  tbl
171
171
  )}" ${where}`;
172
172
  sql_log(sql, values);
173
- const tq = await getMyClient().query(sql, values);
173
+ const tq = await getMyClient(opts).query(sql, values);
174
174
 
175
175
  return parseInt(tq.rows[0].count);
176
176
  };
@@ -201,7 +201,7 @@ const getVersion = async (short) => {
201
201
  */
202
202
  const deleteWhere = async (tbl, whereObj, opts = Object.create(null)) => {
203
203
  const { where, values } = mkWhere(whereObj);
204
- const sql = `delete FROM "${getTenantSchema()}"."${sqlsanitize(
204
+ const sql = `delete FROM "${opts.schema || getTenantSchema()}"."${sqlsanitize(
205
205
  tbl
206
206
  )}" ${where}`;
207
207
  sql_log(sql, values);
@@ -282,7 +282,7 @@ const update = async (tbl, obj, id, opts = Object.create(null)) => {
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
284
  valList.push(id === "undefined" ? obj[opts.pk_name || "id"] : id);
285
- const q = `update "${getTenantSchema()}"."${sqlsanitize(
285
+ const q = `update "${opts.schema || getTenantSchema()}"."${sqlsanitize(
286
286
  tbl
287
287
  )}" set ${assigns} where ${ppPK(opts.pk_name)}=$${kvs.length + 1}`;
288
288
  sql_log(q, valList);