@saltcorn/sql 0.4.3 → 0.4.4

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/index.js +16 -11
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -96,18 +96,23 @@ const run = async (
96
96
  } else if (typeof state[sp] === "undefined") phValues.push(null);
97
97
  else phValues.push(state[sp]);
98
98
  });
99
-
100
- const client = is_sqlite ? db : await db.getClient();
101
- await client.query(`BEGIN;`);
102
- if (!is_sqlite) {
103
- await client.query(`SET LOCAL search_path TO "${db.getTenantSchema()}";`);
104
- await client.query(`SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;`);
99
+ let qres, client;
100
+ try {
101
+ client = is_sqlite ? db : await db.getClient();
102
+ await client.query(`BEGIN;`);
103
+ if (!is_sqlite) {
104
+ await client.query(`SET LOCAL search_path TO "${db.getTenantSchema()}";`);
105
+ await client.query(
106
+ `SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;`
107
+ );
108
+ }
109
+ qres = await client.query(sql, phValues);
110
+ } catch (e) {
111
+ throw e;
112
+ } finally {
113
+ await client.query(`ROLLBACK;`);
114
+ if (!is_sqlite) client.release(true);
105
115
  }
106
- const qres = await client.query(sql, phValues);
107
-
108
- await client.query(`ROLLBACK;`);
109
-
110
- if (!is_sqlite) client.release(true);
111
116
  switch (output_type) {
112
117
  case "HTML":
113
118
  const template = _.template(html_code || "", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/sql",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Actions and views based on SQL",
5
5
  "main": "index.js",
6
6
  "dependencies": {