@saltcorn/postgres 0.7.3-beta.5 → 0.7.3
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 +45 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saltcorn/postgres",
|
|
3
|
-
"version": "0.7.3
|
|
3
|
+
"version": "0.7.3",
|
|
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.7.3
|
|
15
|
+
"@saltcorn/db-common": "0.7.3",
|
|
16
16
|
"pg": "^8.2.1",
|
|
17
17
|
"pg-copy-streams": "^5.1.1"
|
|
18
18
|
},
|
package/postgres.js
CHANGED
|
@@ -379,6 +379,45 @@ const slugify = (s) =>
|
|
|
379
379
|
.replace(/\s+/g, "-")
|
|
380
380
|
.replace(/[^\w-]/g, "");
|
|
381
381
|
|
|
382
|
+
/**
|
|
383
|
+
*
|
|
384
|
+
* @returns
|
|
385
|
+
*/
|
|
386
|
+
const listTables = async () => {
|
|
387
|
+
const tq = await pool.query(
|
|
388
|
+
`SELECT table_name FROM information_schema.tables WHERE table_schema = '${getTenantSchema()}'`
|
|
389
|
+
);
|
|
390
|
+
return tq.rows.map((row) => {
|
|
391
|
+
return { name: row.table_name };
|
|
392
|
+
});
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
*
|
|
397
|
+
* @returns
|
|
398
|
+
*/
|
|
399
|
+
const listUserDefinedTables = async () => {
|
|
400
|
+
const tq = await pool.query(
|
|
401
|
+
`SELECT table_name FROM information_schema.tables WHERE table_schema = '${getTenantSchema()}' AND table_name NOT LIKE '_sc_%'`
|
|
402
|
+
);
|
|
403
|
+
return tq.rows.map((row) => {
|
|
404
|
+
return { name: row.table_name };
|
|
405
|
+
});
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
*
|
|
410
|
+
* @returns
|
|
411
|
+
*/
|
|
412
|
+
const listScTables = async () => {
|
|
413
|
+
const tq = await pool.query(
|
|
414
|
+
`SELECT table_name FROM information_schema.tables WHERE table_schema = '${getTenantSchema()}' AND table_name LIKE '_sc_%'`
|
|
415
|
+
);
|
|
416
|
+
return tq.rows.map((row) => {
|
|
417
|
+
return { name: row.table_name };
|
|
418
|
+
});
|
|
419
|
+
};
|
|
420
|
+
|
|
382
421
|
const postgresExports = {
|
|
383
422
|
pool,
|
|
384
423
|
/**
|
|
@@ -412,6 +451,9 @@ const postgresExports = {
|
|
|
412
451
|
getVersion,
|
|
413
452
|
copyFrom,
|
|
414
453
|
slugify,
|
|
454
|
+
listTables,
|
|
455
|
+
listScTables,
|
|
456
|
+
listUserDefinedTables,
|
|
415
457
|
};
|
|
416
458
|
|
|
417
459
|
module.exports = (getConnectObjectPara) => {
|
|
@@ -420,8 +462,9 @@ module.exports = (getConnectObjectPara) => {
|
|
|
420
462
|
const connectObj = getConnectObject();
|
|
421
463
|
if (connectObj) {
|
|
422
464
|
pool = new Pool(connectObj);
|
|
423
|
-
getTenantSchema = require("@saltcorn/db-common/tenants")(
|
|
424
|
-
|
|
465
|
+
getTenantSchema = require("@saltcorn/db-common/tenants")(
|
|
466
|
+
connectObj
|
|
467
|
+
).getTenantSchema;
|
|
425
468
|
postgresExports.pool = pool;
|
|
426
469
|
} else {
|
|
427
470
|
throw new Error("Unable to retrieve a database connection object.");
|