@malloydata/db-postgres 0.0.22-dev230207180844 → 0.0.22-dev230207183024

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.
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { PostgresConnection, PooledPostgresConnection, } from "./postgres_connection";
1
+ export { PostgresConnection, PooledPostgresConnection } from "./postgres_connection";
@@ -1,4 +1,4 @@
1
- import { PersistSQLResults, RunSQLOptions, StreamingConnection, StructDef, MalloyQueryData, QueryData, PooledConnection, SQLBlock, Connection, QueryDataRow } from "@malloydata/malloy";
1
+ import { Connection, MalloyQueryData, PersistSQLResults, PooledConnection, QueryData, QueryDataRow, RunSQLOptions, SQLBlock, StreamingConnection, StructDef } from "@malloydata/malloy";
2
2
  import { Client } from "pg";
3
3
  interface PostgresQueryConfiguration {
4
4
  rowLimit?: number;
@@ -61,29 +61,29 @@ const pg_query_stream_1 = __importDefault(require("pg-query-stream"));
61
61
  const crypto_1 = require("crypto");
62
62
  const postgresToMalloyTypes = {
63
63
  "character varying": "string",
64
- name: "string",
65
- text: "string",
66
- date: "date",
67
- integer: "number",
68
- bigint: "number",
64
+ "name": "string",
65
+ "text": "string",
66
+ "date": "date",
67
+ "integer": "number",
68
+ "bigint": "number",
69
69
  "double precision": "number",
70
70
  "timestamp without time zone": "timestamp",
71
- oid: "string",
72
- boolean: "boolean",
71
+ "oid": "string",
72
+ "boolean": "boolean",
73
73
  // ARRAY: "string",
74
74
  "timestamp with time zone": "timestamp",
75
- timestamp: "timestamp",
75
+ "timestamp": "timestamp",
76
76
  '"char"': "string",
77
- character: "string",
78
- smallint: "number",
79
- xid: "string",
80
- real: "number",
81
- interval: "string",
82
- inet: "string",
83
- regtype: "string",
84
- numeric: "number",
85
- bytea: "string",
86
- pg_ndistinct: "number",
77
+ "character": "string",
78
+ "smallint": "number",
79
+ "xid": "string",
80
+ "real": "number",
81
+ "interval": "string",
82
+ "inet": "string",
83
+ "regtype": "string",
84
+ "numeric": "number",
85
+ "bytea": "string",
86
+ "pg_ndistinct": "number"
87
87
  };
88
88
  const DEFAULT_PAGE_SIZE = 1000;
89
89
  const SCHEMA_PAGE_SIZE = 1000;
@@ -131,12 +131,12 @@ class PostgresConnection {
131
131
  if (!inCache) {
132
132
  try {
133
133
  inCache = {
134
- schema: await this.getTableSchema(tableURL),
134
+ "schema": await this.getTableSchema(tableURL)
135
135
  };
136
136
  this.schemaCache.set(tableURL, inCache);
137
137
  }
138
138
  catch (error) {
139
- inCache = { error: error.message };
139
+ inCache = { "error": error.message };
140
140
  }
141
141
  }
142
142
  if (inCache.schema !== undefined) {
@@ -154,11 +154,11 @@ class PostgresConnection {
154
154
  if (!inCache) {
155
155
  try {
156
156
  inCache = {
157
- structDef: await this.getSQLBlockSchema(sqlRef),
157
+ "structDef": await this.getSQLBlockSchema(sqlRef)
158
158
  };
159
159
  }
160
160
  catch (error) {
161
- inCache = { error: error.message };
161
+ inCache = { "error": error.message };
162
162
  }
163
163
  this.sqlSchemaCache.set(key, inCache);
164
164
  }
@@ -167,11 +167,11 @@ class PostgresConnection {
167
167
  async getClient() {
168
168
  const config = await this.readConfig();
169
169
  return new pg_1.Client({
170
- user: config.username,
171
- password: config.password,
172
- database: config.databaseName,
173
- port: config.port,
174
- host: config.host,
170
+ "user": config.username,
171
+ "password": config.password,
172
+ "database": config.databaseName,
173
+ "port": config.port,
174
+ "host": config.host
175
175
  });
176
176
  }
177
177
  async runPostgresQuery(sqlCommand, _pageSize, _rowIndex, deJSON) {
@@ -187,23 +187,26 @@ class PostgresConnection {
187
187
  }
188
188
  }
189
189
  await client.end();
190
- return { rows: result.rows, totalRows: result.rows.length };
190
+ return {
191
+ "rows": result.rows,
192
+ "totalRows": result.rows.length
193
+ };
191
194
  }
192
195
  async getSQLBlockSchema(sqlRef) {
193
196
  const structDef = {
194
- type: "struct",
195
- dialect: "postgres",
196
- name: sqlRef.name,
197
- structSource: {
198
- type: "sql",
199
- method: "subquery",
200
- sqlBlock: sqlRef,
197
+ "type": "struct",
198
+ "dialect": "postgres",
199
+ "name": sqlRef.name,
200
+ "structSource": {
201
+ "type": "sql",
202
+ "method": "subquery",
203
+ "sqlBlock": sqlRef
201
204
  },
202
- structRelationship: {
203
- type: "basetable",
204
- connectionName: this.name,
205
+ "structRelationship": {
206
+ "type": "basetable",
207
+ "connectionName": this.name
205
208
  },
206
- fields: [],
209
+ "fields": []
207
210
  };
208
211
  const tempTableName = `tmp${(0, crypto_1.randomUUID)()}`.replace(/-/g, "");
209
212
  const infoQuery = `
@@ -230,27 +233,31 @@ class PostgresConnection {
230
233
  if (postgresDataType === "ARRAY") {
231
234
  malloyType = postgresToMalloyTypes[row["element_type"]];
232
235
  s = {
233
- type: "struct",
234
- name: row["column_name"],
235
- dialect: this.dialectName,
236
- structRelationship: { type: "nested", field: name, isArray: true },
237
- structSource: { type: "nested" },
238
- fields: [],
236
+ "type": "struct",
237
+ "name": row["column_name"],
238
+ "dialect": this.dialectName,
239
+ "structRelationship": {
240
+ "type": "nested",
241
+ "field": name,
242
+ "isArray": true
243
+ },
244
+ "structSource": { "type": "nested" },
245
+ "fields": []
239
246
  };
240
247
  structDef.fields.push(s);
241
248
  name = "value";
242
249
  }
243
250
  if (malloyType !== undefined) {
244
251
  s.fields.push({
245
- type: malloyType,
246
- name,
252
+ "type": malloyType,
253
+ name
247
254
  });
248
255
  }
249
256
  else {
250
257
  s.fields.push({
251
258
  name,
252
- type: "string",
253
- e: [`'Postgres type "${postgresDataType}" not supported by Malloy'`],
259
+ "type": "string",
260
+ "e": [`'Postgres type "${postgresDataType}" not supported by Malloy'`]
254
261
  });
255
262
  }
256
263
  }
@@ -258,15 +265,15 @@ class PostgresConnection {
258
265
  async getTableSchema(tableURL) {
259
266
  const { tablePath } = (0, malloy_1.parseTableURI)(tableURL);
260
267
  const structDef = {
261
- type: "struct",
262
- name: tableURL,
263
- dialect: "postgres",
264
- structSource: { type: "table", tablePath },
265
- structRelationship: {
266
- type: "basetable",
267
- connectionName: this.name,
268
+ "type": "struct",
269
+ "name": tableURL,
270
+ "dialect": "postgres",
271
+ "structSource": { "type": "table", tablePath },
272
+ "structRelationship": {
273
+ "type": "basetable",
274
+ "connectionName": this.name
268
275
  },
269
- fields: [],
276
+ "fields": []
270
277
  };
271
278
  const [schema, table] = tablePath.split(".");
272
279
  if (table === undefined) {
@@ -346,7 +353,10 @@ class PooledPostgresConnection extends PostgresConnection {
346
353
  result.rows[i] = result.rows[i].row;
347
354
  }
348
355
  }
349
- return { rows: result.rows, totalRows: result.rows.length };
356
+ return {
357
+ "rows": result.rows,
358
+ "totalRows": result.rows.length
359
+ };
350
360
  }
351
361
  async getClientFromPool() {
352
362
  return await new Promise((resolve, reject) => this.pool.connect((error, client, releaseClient) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/db-postgres",
3
- "version": "0.0.22-dev230207180844",
3
+ "version": "0.0.22-dev230207183024",
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.22-dev230207180844",
22
+ "@malloydata/malloy": "^0.0.22-dev230207183024",
23
23
  "@types/pg": "^8.6.1",
24
24
  "pg": "^8.7.1",
25
25
  "pg-query-stream": "4.2.3"