@saltcorn/postgres 0.8.2 → 0.8.3-alpha.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.
- package/package.json +2 -2
- package/postgres.js +10 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saltcorn/postgres",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3-alpha.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.8.
|
|
15
|
+
"@saltcorn/db-common": "0.8.3-alpha.1",
|
|
16
16
|
"pg": "^8.2.1",
|
|
17
17
|
"pg-copy-streams": "^5.1.1"
|
|
18
18
|
},
|
package/postgres.js
CHANGED
|
@@ -182,12 +182,13 @@ const insert = async (tbl, obj, opts = {}) => {
|
|
|
182
182
|
const sql =
|
|
183
183
|
valPosList.length > 0
|
|
184
184
|
? `insert into "${schema}"."${sqlsanitize(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
tbl
|
|
186
|
+
)}"(${fnameList}) values(${valPosList.join()}) returning ${
|
|
187
|
+
opts.noid ? "*" : opts.pk_name || "id"
|
|
188
|
+
}`
|
|
188
189
|
: `insert into "${schema}"."${sqlsanitize(
|
|
189
|
-
|
|
190
|
-
|
|
190
|
+
tbl
|
|
191
|
+
)}" DEFAULT VALUES returning ${opts.noid ? "*" : opts.pk_name || "id"}`;
|
|
191
192
|
sql_log(sql, valList);
|
|
192
193
|
const { rows } = await (opts.client || pool).query(sql, valList);
|
|
193
194
|
if (opts.noid) return;
|
|
@@ -204,6 +205,7 @@ const insert = async (tbl, obj, opts = {}) => {
|
|
|
204
205
|
*/
|
|
205
206
|
const update = async (tbl, obj, id, opts = {}) => {
|
|
206
207
|
const kvs = Object.entries(obj);
|
|
208
|
+
if (kvs.length === 0) return;
|
|
207
209
|
const assigns = kvs
|
|
208
210
|
.map(([k, v], ix) => `"${sqlsanitize(k)}"=$${ix + 1}`)
|
|
209
211
|
.join();
|
|
@@ -227,6 +229,7 @@ const update = async (tbl, obj, id, opts = {}) => {
|
|
|
227
229
|
*/
|
|
228
230
|
const updateWhere = async (tbl, obj, whereObj) => {
|
|
229
231
|
const kvs = Object.entries(obj);
|
|
232
|
+
if (kvs.length === 0) return;
|
|
230
233
|
const { where, values } = mkWhere(whereObj, false, kvs.length);
|
|
231
234
|
const assigns = kvs
|
|
232
235
|
.map(([k, v], ix) => `"${sqlsanitize(k)}"=$${ix + 1}`)
|
|
@@ -305,8 +308,8 @@ const add_unique_constraint = async (table_name, field_names) => {
|
|
|
305
308
|
)}" add CONSTRAINT "${sqlsanitize(table_name)}_${field_names
|
|
306
309
|
.map((f) => sqlsanitize(f))
|
|
307
310
|
.join("_")}_unique" UNIQUE (${field_names
|
|
308
|
-
|
|
309
|
-
|
|
311
|
+
.map((f) => `"${sqlsanitize(f)}"`)
|
|
312
|
+
.join(",")});`;
|
|
310
313
|
sql_log(sql);
|
|
311
314
|
await pool.query(sql);
|
|
312
315
|
};
|