@malloydata/db-postgres 0.0.120-dev240131223846 → 0.0.121-dev240201150428

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,9 +1,5 @@
1
- import { Connection, FetchSchemaOptions, MalloyQueryData, PersistSQLResults, PooledConnection, QueryDataRow, QueryRunStats, RunSQLOptions, SQLBlock, StreamingConnection, StructDef } from '@malloydata/malloy';
1
+ import { Connection, ConnectionConfig, FetchSchemaOptions, MalloyQueryData, PersistSQLResults, PooledConnection, QueryDataRow, QueryOptionsReader, QueryRunStats, RunSQLOptions, SQLBlock, StreamingConnection, StructDef } from '@malloydata/malloy';
2
2
  import { Client, Pool } from 'pg';
3
- interface PostgresQueryConfiguration {
4
- rowLimit?: number;
5
- }
6
- type PostgresQueryConfigurationReader = PostgresQueryConfiguration | (() => PostgresQueryConfiguration) | (() => Promise<PostgresQueryConfiguration>);
7
3
  interface PostgresConnectionConfiguration {
8
4
  host?: string;
9
5
  port?: number;
@@ -13,14 +9,17 @@ interface PostgresConnectionConfiguration {
13
9
  connectionString?: string;
14
10
  }
15
11
  type PostgresConnectionConfigurationReader = PostgresConnectionConfiguration | (() => Promise<PostgresConnectionConfiguration>);
12
+ export interface PostgresConnectionOptions extends ConnectionConfig, PostgresConnectionConfiguration {
13
+ }
16
14
  export declare class PostgresConnection implements Connection, StreamingConnection, PersistSQLResults {
17
15
  readonly name: string;
18
- private queryConfigReader;
16
+ private queryOptionsReader;
19
17
  private configReader;
20
18
  private readonly dialect;
21
19
  private schemaCache;
22
20
  private sqlSchemaCache;
23
- constructor(name: string, queryConfigReader?: PostgresQueryConfigurationReader, configReader?: PostgresConnectionConfigurationReader);
21
+ constructor(options: PostgresConnectionOptions, queryOptionsReader?: QueryOptionsReader);
22
+ constructor(name: string, queryOptionsReader?: QueryOptionsReader, configReader?: PostgresConnectionConfigurationReader);
24
23
  private readQueryConfig;
25
24
  protected readConfig(): Promise<PostgresConnectionConfiguration>;
26
25
  get dialectName(): string;
@@ -54,7 +53,8 @@ export declare class PostgresConnection implements Connection, StreamingConnecti
54
53
  }
55
54
  export declare class PooledPostgresConnection extends PostgresConnection implements PooledConnection {
56
55
  private _pool;
57
- constructor(name: string, queryConfigReader?: PostgresQueryConfigurationReader, configReader?: PostgresConnectionConfigurationReader);
56
+ constructor(options: PostgresConnectionOptions, queryOptionsReader?: QueryOptionsReader);
57
+ constructor(name: string, queryOptionsReader?: QueryOptionsReader, configReader?: PostgresConnectionConfigurationReader);
58
58
  isPool(): true;
59
59
  drain(): Promise<void>;
60
60
  getPool(): Promise<Pool>;
@@ -62,20 +62,33 @@ const crypto_1 = require("crypto");
62
62
  const DEFAULT_PAGE_SIZE = 1000;
63
63
  const SCHEMA_PAGE_SIZE = 1000;
64
64
  class PostgresConnection {
65
- constructor(name, queryConfigReader = {}, configReader = {}) {
66
- this.name = name;
67
- this.queryConfigReader = queryConfigReader;
68
- this.configReader = configReader;
65
+ constructor(arg, queryOptionsReader, configReader) {
66
+ this.queryOptionsReader = {};
67
+ this.configReader = {};
69
68
  this.dialect = new malloy_1.PostgresDialect();
70
69
  this.schemaCache = new Map();
71
70
  this.sqlSchemaCache = new Map();
71
+ if (typeof arg === 'string') {
72
+ this.name = arg;
73
+ if (configReader) {
74
+ this.configReader = configReader;
75
+ }
76
+ }
77
+ else {
78
+ const { name, ...configReader } = arg;
79
+ this.name = name;
80
+ this.configReader = configReader;
81
+ }
82
+ if (queryOptionsReader) {
83
+ this.queryOptionsReader = queryOptionsReader;
84
+ }
72
85
  }
73
86
  async readQueryConfig() {
74
- if (this.queryConfigReader instanceof Function) {
75
- return this.queryConfigReader();
87
+ if (this.queryOptionsReader instanceof Function) {
88
+ return this.queryOptionsReader();
76
89
  }
77
90
  else {
78
- return this.queryConfigReader;
91
+ return this.queryOptionsReader;
79
92
  }
80
93
  }
81
94
  async readConfig() {
@@ -331,8 +344,13 @@ class PostgresConnection {
331
344
  }
332
345
  exports.PostgresConnection = PostgresConnection;
333
346
  class PooledPostgresConnection extends PostgresConnection {
334
- constructor(name, queryConfigReader = {}, configReader = {}) {
335
- super(name, queryConfigReader, configReader);
347
+ constructor(arg, queryOptionsReader, configReader) {
348
+ if (typeof arg === 'string') {
349
+ super(arg, queryOptionsReader, configReader);
350
+ }
351
+ else {
352
+ super(arg, queryOptionsReader);
353
+ }
336
354
  }
337
355
  isPool() {
338
356
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/db-postgres",
3
- "version": "0.0.120-dev240131223846",
3
+ "version": "0.0.121-dev240201150428",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "prepublishOnly": "npm run build"
23
23
  },
24
24
  "dependencies": {
25
- "@malloydata/malloy": "^0.0.120-dev240131223846",
25
+ "@malloydata/malloy": "^0.0.121-dev240201150428",
26
26
  "@types/pg": "^8.6.1",
27
27
  "pg": "^8.7.1",
28
28
  "pg-query-stream": "4.2.3"