@saltcorn/postgres 1.0.0-beta.13 → 1.0.0-beta.15
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 +8 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saltcorn/postgres",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.15",
|
|
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.0.0-beta.
|
|
15
|
+
"@saltcorn/db-common": "1.0.0-beta.15",
|
|
16
16
|
"pg": "^8.2.1",
|
|
17
17
|
"pg-copy-streams": "^5.1.1",
|
|
18
18
|
"replacestream": "4.0.3"
|
package/postgres.js
CHANGED
|
@@ -64,7 +64,7 @@ const close = async () => {
|
|
|
64
64
|
* @param {object} [connObj = {}] - connection object
|
|
65
65
|
* @returns {Promise<void>}
|
|
66
66
|
*/
|
|
67
|
-
const changeConnection = async (connObj =
|
|
67
|
+
const changeConnection = async (connObj = Object.create(null)) => {
|
|
68
68
|
await close();
|
|
69
69
|
pool = new Pool(getConnectObject(connObj));
|
|
70
70
|
};
|
|
@@ -93,7 +93,7 @@ const rollback = async () => {
|
|
|
93
93
|
* @param {object} [selectopts = {}] - select options
|
|
94
94
|
* @returns {Promise<*>} return rows
|
|
95
95
|
*/
|
|
96
|
-
const select = async (tbl, whereObj, selectopts =
|
|
96
|
+
const select = async (tbl, whereObj, selectopts = Object.create(null)) => {
|
|
97
97
|
const { where, values } = mkWhere(whereObj);
|
|
98
98
|
const schema = selectopts.schema || getTenantSchema();
|
|
99
99
|
const sql = `SELECT ${
|
|
@@ -167,7 +167,7 @@ const getVersion = async (short) => {
|
|
|
167
167
|
* @param {object} [opts = {}]
|
|
168
168
|
* @returns {Promise<object[]>} result of delete execution
|
|
169
169
|
*/
|
|
170
|
-
const deleteWhere = async (tbl, whereObj, opts =
|
|
170
|
+
const deleteWhere = async (tbl, whereObj, opts = Object.create(null)) => {
|
|
171
171
|
const { where, values } = mkWhere(whereObj);
|
|
172
172
|
const sql = `delete FROM "${getTenantSchema()}"."${sqlsanitize(
|
|
173
173
|
tbl
|
|
@@ -186,7 +186,7 @@ const deleteWhere = async (tbl, whereObj, opts = {}) => {
|
|
|
186
186
|
* @param {object} [opts = {}] - columns attributes
|
|
187
187
|
* @returns {Promise<string>} returns primary key column or Id column value. If primary key column is not defined then return value of Id column.
|
|
188
188
|
*/
|
|
189
|
-
const insert = async (tbl, obj, opts =
|
|
189
|
+
const insert = async (tbl, obj, opts = Object.create(null)) => {
|
|
190
190
|
const kvs = Object.entries(obj);
|
|
191
191
|
const fnameList = kvs.map(([k, v]) => `"${sqlsanitize(k)}"`).join();
|
|
192
192
|
var valPosList = [];
|
|
@@ -231,7 +231,7 @@ const insert = async (tbl, obj, opts = {}) => {
|
|
|
231
231
|
* @param {object} [opts = {}] - columns attributes
|
|
232
232
|
* @returns {Promise<void>} no result
|
|
233
233
|
*/
|
|
234
|
-
const update = async (tbl, obj, id, opts =
|
|
234
|
+
const update = async (tbl, obj, id, opts = Object.create(null)) => {
|
|
235
235
|
const kvs = Object.entries(obj);
|
|
236
236
|
if (kvs.length === 0) return;
|
|
237
237
|
const assigns = kvs
|
|
@@ -256,7 +256,7 @@ const update = async (tbl, obj, id, opts = {}) => {
|
|
|
256
256
|
* @param {object} opts - can contain a db client for transactions
|
|
257
257
|
* @returns {Promise<void>} no result
|
|
258
258
|
*/
|
|
259
|
-
const updateWhere = async (tbl, obj, whereObj, opts =
|
|
259
|
+
const updateWhere = async (tbl, obj, whereObj, opts = Object.create(null)) => {
|
|
260
260
|
const kvs = Object.entries(obj);
|
|
261
261
|
if (kvs.length === 0) return;
|
|
262
262
|
const { where, values } = mkWhere(whereObj, false, kvs.length);
|
|
@@ -280,7 +280,7 @@ const updateWhere = async (tbl, obj, whereObj, opts = {}) => {
|
|
|
280
280
|
* @returns {Promise<object>} return first record from sql result
|
|
281
281
|
* @throws {Error}
|
|
282
282
|
*/
|
|
283
|
-
const selectOne = async (tbl, where, selectopts =
|
|
283
|
+
const selectOne = async (tbl, where, selectopts = Object.create(null)) => {
|
|
284
284
|
const rows = await select(tbl, where, { ...selectopts, limit: 1 });
|
|
285
285
|
if (rows.length === 0) {
|
|
286
286
|
const w = mkWhere(where);
|
|
@@ -295,7 +295,7 @@ const selectOne = async (tbl, where, selectopts = {}) => {
|
|
|
295
295
|
* @param {object} [selectopts = {}] - select options
|
|
296
296
|
* @returns {Promise<null|object>} - null if no record or first record data
|
|
297
297
|
*/
|
|
298
|
-
const selectMaybeOne = async (tbl, where, selectopts =
|
|
298
|
+
const selectMaybeOne = async (tbl, where, selectopts = Object.create(null)) => {
|
|
299
299
|
const rows = await select(tbl, where, { ...selectopts, limit: 1 });
|
|
300
300
|
if (rows.length === 0) return null;
|
|
301
301
|
else return rows[0];
|