@saltcorn/postgres 1.1.4-beta.1 → 1.1.4-beta.11

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 +15 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/postgres",
3
- "version": "1.1.4-beta.1",
3
+ "version": "1.1.4-beta.11",
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.1.4-beta.1",
15
+ "@saltcorn/db-common": "1.1.4-beta.11",
16
16
  "pg": "^8.13.1",
17
17
  "pg-copy-streams": "^6.0.6",
18
18
  "replacestream": "4.0.3"
package/postgres.js CHANGED
@@ -575,6 +575,20 @@ const withTransaction = async (f, onError) => {
575
575
  }
576
576
  };
577
577
 
578
+ const tryCatchInTransaction = async (f, onError) => {
579
+ const rndid = Math.floor(Math.random() * 16777215).toString(16);
580
+ const reqCon = getRequestContext();
581
+ if (reqCon?.client) await query(`SAVEPOINT sp${rndid}`);
582
+ try {
583
+ return await f();
584
+ } catch (error) {
585
+ if (reqCon?.client) await query(`ROLLBACK TO SAVEPOINT sp${rndid}`);
586
+ await onError(error);
587
+ } finally {
588
+ if (reqCon?.client) await query(`RELEASE SAVEPOINT sp${rndid}`);
589
+ }
590
+ };
591
+
578
592
  const query = (text, params) => {
579
593
  sql_log(text, params);
580
594
  return getMyClient().query(text, params);
@@ -624,6 +638,7 @@ const postgresExports = {
624
638
  listUserDefinedTables,
625
639
  truncate,
626
640
  withTransaction,
641
+ tryCatchInTransaction,
627
642
  };
628
643
 
629
644
  module.exports = (getConnectObjectPara) => {