@saltcorn/postgres 0.9.1-beta.8 → 0.9.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 +2 -2
  2. package/postgres.js +4 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/postgres",
3
- "version": "0.9.1-beta.8",
3
+ "version": "0.9.1",
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.9.1-beta.8",
15
+ "@saltcorn/db-common": "0.9.1",
16
16
  "pg": "^8.2.1",
17
17
  "pg-copy-streams": "^5.1.1"
18
18
  },
package/postgres.js CHANGED
@@ -188,6 +188,7 @@ const insert = async (tbl, obj, opts = {}) => {
188
188
  var valPosList = [];
189
189
  var valList = [];
190
190
  const schema = opts.schema || getTenantSchema();
191
+ let conflict = "";
191
192
  kvs.forEach(([k, v]) => {
192
193
  if (v && v.next_version_by_id) {
193
194
  valPosList.push(
@@ -195,6 +196,7 @@ const insert = async (tbl, obj, opts = {}) => {
195
196
  tbl
196
197
  )}" where id=${+v.next_version_by_id}), 0)+1`
197
198
  );
199
+ if (opts.onConflictDoNothing) conflict = "on conflict do nothing ";
198
200
  } else {
199
201
  valList.push(v);
200
202
  valPosList.push(`$${valList.length}`);
@@ -204,7 +206,7 @@ const insert = async (tbl, obj, opts = {}) => {
204
206
  valPosList.length > 0
205
207
  ? `insert into "${schema}"."${sqlsanitize(
206
208
  tbl
207
- )}"(${fnameList}) values(${valPosList.join()}) returning ${
209
+ )}"(${fnameList}) values(${valPosList.join()}) ${conflict}returning ${
208
210
  opts.noid ? "*" : opts.pk_name || "id"
209
211
  }`
210
212
  : `insert into "${schema}"."${sqlsanitize(
@@ -213,6 +215,7 @@ const insert = async (tbl, obj, opts = {}) => {
213
215
  sql_log(sql, valList);
214
216
  const { rows } = await (client || opts.client || pool).query(sql, valList);
215
217
  if (opts.noid) return;
218
+ else if (conflict && rows.length === 0) return;
216
219
  else return rows[0][opts.pk_name || "id"];
217
220
  };
218
221