@malloydata/db-postgres 0.0.34-dev230523182411 → 0.0.34
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.
|
@@ -13,6 +13,7 @@ interface PostgresConnectionConfiguration {
|
|
|
13
13
|
}
|
|
14
14
|
declare type PostgresConnectionConfigurationReader = PostgresConnectionConfiguration | (() => Promise<PostgresConnectionConfiguration>);
|
|
15
15
|
export declare class PostgresConnection implements Connection, StreamingConnection, PersistSQLResults {
|
|
16
|
+
private isSetup;
|
|
16
17
|
private schemaCache;
|
|
17
18
|
private sqlSchemaCache;
|
|
18
19
|
private queryConfigReader;
|
|
@@ -43,6 +44,7 @@ export declare class PostgresConnection implements Connection, StreamingConnecti
|
|
|
43
44
|
private getTableSchema;
|
|
44
45
|
executeSQLRaw(query: string): Promise<QueryData>;
|
|
45
46
|
test(): Promise<void>;
|
|
47
|
+
connectionSetup(): Promise<void>;
|
|
46
48
|
runSQL(sql: string, { rowLimit }?: RunSQLOptions, rowIndex?: number): Promise<MalloyQueryData>;
|
|
47
49
|
runSQLStream(sqlCommand: string, options?: {
|
|
48
50
|
rowLimit?: number;
|
|
@@ -71,7 +71,6 @@ const postgresToMalloyTypes = {
|
|
|
71
71
|
'oid': 'string',
|
|
72
72
|
'boolean': 'boolean',
|
|
73
73
|
// ARRAY: "string",
|
|
74
|
-
'timestamp with time zone': 'timestamp',
|
|
75
74
|
'timestamp': 'timestamp',
|
|
76
75
|
'"char"': 'string',
|
|
77
76
|
'character': 'string',
|
|
@@ -89,6 +88,7 @@ const DEFAULT_PAGE_SIZE = 1000;
|
|
|
89
88
|
const SCHEMA_PAGE_SIZE = 1000;
|
|
90
89
|
class PostgresConnection {
|
|
91
90
|
constructor(name, queryConfigReader = {}, configReader = {}) {
|
|
91
|
+
this.isSetup = false;
|
|
92
92
|
this.schemaCache = new Map();
|
|
93
93
|
this.sqlSchemaCache = new Map();
|
|
94
94
|
this.queryConfigReader = queryConfigReader;
|
|
@@ -177,6 +177,7 @@ class PostgresConnection {
|
|
|
177
177
|
async runPostgresQuery(sqlCommand, _pageSize, _rowIndex, deJSON) {
|
|
178
178
|
const client = await this.getClient();
|
|
179
179
|
await client.connect();
|
|
180
|
+
await this.connectionSetup();
|
|
180
181
|
let result = await client.query(sqlCommand);
|
|
181
182
|
if (Array.isArray(result)) {
|
|
182
183
|
result = result.pop();
|
|
@@ -295,10 +296,17 @@ class PostgresConnection {
|
|
|
295
296
|
async test() {
|
|
296
297
|
await this.executeSQLRaw('SELECT 1');
|
|
297
298
|
}
|
|
299
|
+
async connectionSetup() {
|
|
300
|
+
if (!this.isSetup) {
|
|
301
|
+
this.executeSQLRaw("SET TIME ZONE 'UTC'");
|
|
302
|
+
this.isSetup = true;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
298
305
|
async runSQL(sql, { rowLimit } = {}, rowIndex = 0) {
|
|
299
306
|
var _a;
|
|
300
307
|
const config = await this.readQueryConfig();
|
|
301
|
-
|
|
308
|
+
const the_return = await this.runPostgresQuery(sql, (_a = rowLimit !== null && rowLimit !== void 0 ? rowLimit : config.rowLimit) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_SIZE, rowIndex, true);
|
|
309
|
+
return the_return;
|
|
302
310
|
}
|
|
303
311
|
async *runSQLStream(sqlCommand, options) {
|
|
304
312
|
const query = new pg_query_stream_1.default(sqlCommand);
|
|
@@ -333,6 +341,7 @@ class PooledPostgresConnection extends PostgresConnection {
|
|
|
333
341
|
constructor(name) {
|
|
334
342
|
super(name);
|
|
335
343
|
this.pool = new pg_1.Pool();
|
|
344
|
+
this.pool.on('acquire', client => client.query("SET TIME ZONE 'UTC'"));
|
|
336
345
|
}
|
|
337
346
|
isPool() {
|
|
338
347
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/db-postgres",
|
|
3
|
-
"version": "0.0.34
|
|
3
|
+
"version": "0.0.34",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"prepublishOnly": "npm run build"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@malloydata/malloy": "^0.0.34
|
|
22
|
+
"@malloydata/malloy": "^0.0.34",
|
|
23
23
|
"@types/pg": "^8.6.1",
|
|
24
24
|
"pg": "^8.7.1",
|
|
25
25
|
"pg-query-stream": "4.2.3"
|