-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
51 lines (49 loc) · 1.62 KB
/
Copy pathindex.js
File metadata and controls
51 lines (49 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const { getConnection } = require("./connections");
module.exports = {
sc_plugin_api_version: 1,
table_providers: require("./table-provider.js"),
viewtemplates: [require("./database-browser")],
ready_for_mobile: true,
functions: {
extPgSqlQuery: {
run: async (connection, query, parameters) => {
const sql_log = (...args) => {
console.log(...args);
};
const pool = await getConnection(connection);
const client = await pool.connect();
sql_log("BEGIN;");
await client.query(`BEGIN;`);
if (connection.schema) {
sql_log(`SET LOCAL search_path TO "${connection.schema}";`);
await client.query(
`SET LOCAL search_path TO "${connection.schema}";`,
);
}
sql_log(`SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;`);
await client.query(
`SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;`,
);
sql_log(query, parameters || []);
const qres = await client.query(query, parameters || []);
sql_log("ROLLBACK;");
await client.query(`ROLLBACK;`);
client.release();
return qres;
},
isAsync: true,
description: "Run an SQL query",
arguments: [
{
name: "connection",
type: "JSON",
tstype:
"{host: string, port: number, user: string, password: string, database: string, schema: string}",
required: true,
},
{ name: "sql_query", type: "String", required: true },
{ name: "parameters", type: "JSON", tstype: "any[]" },
],
},
},
};