@saltcorn/sql 0.3.7 → 0.3.8

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 +21 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -133,6 +133,27 @@ module.exports = {
133
133
  plugin_name: "sql",
134
134
  actions: require("./action.js"),
135
135
  table_providers: require("./table-provider.js"),
136
+ functions: {
137
+ sqlQuery: {
138
+ run: async (query, parameters) => {
139
+ const is_sqlite = db.isSQLite;
140
+
141
+ const client = is_sqlite ? db : await db.getClient();
142
+ await client.query(`BEGIN;`);
143
+ if (!is_sqlite) {
144
+ await client.query(
145
+ `SET LOCAL search_path TO "${db.getTenantSchema()}";`
146
+ );
147
+ }
148
+ const qres = await db.query(query, parameters || []);
149
+
150
+ await client.query(`COMMIT;`);
151
+ return qres;
152
+ },
153
+ isAsync: true,
154
+ description: "Run an SQL query",
155
+ },
156
+ },
136
157
  viewtemplates: [
137
158
  {
138
159
  name: "SQLView",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/sql",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "description": "Actions and views based on SQL",
5
5
  "main": "index.js",
6
6
  "dependencies": {