@malloydata/db-postgres 0.0.103-dev231115200636 → 0.0.103
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Connection, MalloyQueryData, PersistSQLResults, PooledConnection, QueryDataRow, QueryRunStats, RunSQLOptions, SQLBlock, StreamingConnection, StructDef } from '@malloydata/malloy';
|
|
2
|
-
import { Client, Pool
|
|
2
|
+
import { Client, Pool } from 'pg';
|
|
3
3
|
import { FetchSchemaOptions } from '@malloydata/malloy-interfaces';
|
|
4
4
|
interface PostgresQueryConfiguration {
|
|
5
5
|
rowLimit?: number;
|
|
@@ -18,7 +18,6 @@ export declare class PostgresConnection implements Connection, StreamingConnecti
|
|
|
18
18
|
private queryConfigReader;
|
|
19
19
|
private configReader;
|
|
20
20
|
private readonly dialect;
|
|
21
|
-
private isSetup;
|
|
22
21
|
private schemaCache;
|
|
23
22
|
private sqlSchemaCache;
|
|
24
23
|
constructor(name: string, queryConfigReader?: PostgresQueryConfigurationReader, configReader?: PostgresConnectionConfigurationReader);
|
|
@@ -45,13 +44,10 @@ export declare class PostgresConnection implements Connection, StreamingConnecti
|
|
|
45
44
|
private getSQLBlockSchema;
|
|
46
45
|
private schemaFromQuery;
|
|
47
46
|
private getTableSchema;
|
|
48
|
-
executeSQLRaw(query: string): Promise<QueryResult>;
|
|
49
47
|
test(): Promise<void>;
|
|
50
48
|
connectionSetup(client: Client): Promise<void>;
|
|
51
49
|
runSQL(sql: string, { rowLimit }?: RunSQLOptions, rowIndex?: number): Promise<MalloyQueryData>;
|
|
52
|
-
runSQLStream(sqlCommand: string,
|
|
53
|
-
rowLimit?: number;
|
|
54
|
-
}): AsyncIterableIterator<QueryDataRow>;
|
|
50
|
+
runSQLStream(sqlCommand: string, { rowLimit, abortSignal }?: RunSQLOptions): AsyncIterableIterator<QueryDataRow>;
|
|
55
51
|
estimateQueryCost(_: string): Promise<QueryRunStats>;
|
|
56
52
|
manifestTemporaryTable(sqlCommand: string): Promise<string>;
|
|
57
53
|
close(): Promise<void>;
|
|
@@ -63,9 +59,7 @@ export declare class PooledPostgresConnection extends PostgresConnection impleme
|
|
|
63
59
|
drain(): Promise<void>;
|
|
64
60
|
getPool(): Promise<Pool>;
|
|
65
61
|
protected runPostgresQuery(sqlCommand: string, _pageSize: number, _rowIndex: number, deJSON: boolean): Promise<MalloyQueryData>;
|
|
66
|
-
runSQLStream(sqlCommand: string,
|
|
67
|
-
rowLimit?: number;
|
|
68
|
-
}): AsyncIterableIterator<QueryDataRow>;
|
|
62
|
+
runSQLStream(sqlCommand: string, { rowLimit, abortSignal }?: RunSQLOptions): AsyncIterableIterator<QueryDataRow>;
|
|
69
63
|
close(): Promise<void>;
|
|
70
64
|
}
|
|
71
65
|
export {};
|
|
@@ -67,7 +67,6 @@ class PostgresConnection {
|
|
|
67
67
|
this.queryConfigReader = queryConfigReader;
|
|
68
68
|
this.configReader = configReader;
|
|
69
69
|
this.dialect = new malloy_1.PostgresDialect();
|
|
70
|
-
this.isSetup = false;
|
|
71
70
|
this.schemaCache = new Map();
|
|
72
71
|
this.sqlSchemaCache = new Map();
|
|
73
72
|
}
|
|
@@ -286,15 +285,8 @@ class PostgresConnection {
|
|
|
286
285
|
}
|
|
287
286
|
return structDef;
|
|
288
287
|
}
|
|
289
|
-
async executeSQLRaw(query) {
|
|
290
|
-
const client = await this.getClient();
|
|
291
|
-
await client.connect();
|
|
292
|
-
const results = await client.query(query);
|
|
293
|
-
await client.end();
|
|
294
|
-
return results;
|
|
295
|
-
}
|
|
296
288
|
async test() {
|
|
297
|
-
await this.
|
|
289
|
+
await this.runSQL('SELECT 1');
|
|
298
290
|
}
|
|
299
291
|
async connectionSetup(client) {
|
|
300
292
|
await client.query("SET TIME ZONE 'UTC'");
|
|
@@ -302,19 +294,19 @@ class PostgresConnection {
|
|
|
302
294
|
async runSQL(sql, { rowLimit } = {}, rowIndex = 0) {
|
|
303
295
|
var _a;
|
|
304
296
|
const config = await this.readQueryConfig();
|
|
305
|
-
|
|
306
|
-
return the_return;
|
|
297
|
+
return this.runPostgresQuery(sql, (_a = rowLimit !== null && rowLimit !== void 0 ? rowLimit : config.rowLimit) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_SIZE, rowIndex, true);
|
|
307
298
|
}
|
|
308
|
-
async *runSQLStream(sqlCommand,
|
|
299
|
+
async *runSQLStream(sqlCommand, { rowLimit, abortSignal } = {}) {
|
|
309
300
|
const query = new pg_query_stream_1.default(sqlCommand);
|
|
310
301
|
const client = await this.getClient();
|
|
311
|
-
client.connect();
|
|
302
|
+
await client.connect();
|
|
312
303
|
const rowStream = client.query(query);
|
|
313
304
|
let index = 0;
|
|
314
305
|
for await (const row of rowStream) {
|
|
315
306
|
yield row.row;
|
|
316
307
|
index += 1;
|
|
317
|
-
if ((
|
|
308
|
+
if ((rowLimit !== undefined && index >= rowLimit) ||
|
|
309
|
+
(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
|
|
318
310
|
query.destroy();
|
|
319
311
|
break;
|
|
320
312
|
}
|
|
@@ -378,7 +370,7 @@ class PooledPostgresConnection extends PostgresConnection {
|
|
|
378
370
|
totalRows: result.rows.length,
|
|
379
371
|
};
|
|
380
372
|
}
|
|
381
|
-
async *runSQLStream(sqlCommand,
|
|
373
|
+
async *runSQLStream(sqlCommand, { rowLimit, abortSignal } = {}) {
|
|
382
374
|
const query = new pg_query_stream_1.default(sqlCommand);
|
|
383
375
|
let index = 0;
|
|
384
376
|
// This is a strange hack... `this.pool.query(query)` seems to return the wrong
|
|
@@ -391,7 +383,8 @@ class PooledPostgresConnection extends PostgresConnection {
|
|
|
391
383
|
for await (const row of resultStream) {
|
|
392
384
|
yield row.row;
|
|
393
385
|
index += 1;
|
|
394
|
-
if ((
|
|
386
|
+
if ((rowLimit !== undefined && index >= rowLimit) ||
|
|
387
|
+
(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
|
|
395
388
|
query.destroy();
|
|
396
389
|
break;
|
|
397
390
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/db-postgres",
|
|
3
|
-
"version": "0.0.103
|
|
3
|
+
"version": "0.0.103",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"prepublishOnly": "npm run build"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@malloydata/malloy": "^0.0.103
|
|
26
|
-
"@malloydata/malloy-interfaces": "^0.0.103
|
|
25
|
+
"@malloydata/malloy": "^0.0.103",
|
|
26
|
+
"@malloydata/malloy-interfaces": "^0.0.103",
|
|
27
27
|
"@types/pg": "^8.6.1",
|
|
28
28
|
"pg": "^8.7.1",
|
|
29
29
|
"pg-query-stream": "4.2.3"
|