@malloydata/db-postgres 0.0.24-dev230224214106 → 0.0.24-dev230301165401

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,5 +1,5 @@
1
- import { Connection, MalloyQueryData, PersistSQLResults, PooledConnection, QueryData, QueryDataRow, RunSQLOptions, SQLBlock, StreamingConnection, StructDef } from "@malloydata/malloy";
2
- import { Client } from "pg";
1
+ import { Connection, MalloyQueryData, PersistSQLResults, PooledConnection, QueryData, QueryDataRow, RunSQLOptions, SQLBlock, StreamingConnection, StructDef } from '@malloydata/malloy';
2
+ import { Client } from 'pg';
3
3
  interface PostgresQueryConfiguration {
4
4
  rowLimit?: number;
5
5
  }
@@ -60,31 +60,31 @@ const pg_1 = require("pg");
60
60
  const pg_query_stream_1 = __importDefault(require("pg-query-stream"));
61
61
  const crypto_1 = require("crypto");
62
62
  const postgresToMalloyTypes = {
63
- "character varying": "string",
64
- "name": "string",
65
- "text": "string",
66
- "date": "date",
67
- "integer": "number",
68
- "bigint": "number",
69
- "double precision": "number",
70
- "timestamp without time zone": "timestamp",
71
- "oid": "string",
72
- "boolean": "boolean",
63
+ 'character varying': 'string',
64
+ name: 'string',
65
+ text: 'string',
66
+ date: 'date',
67
+ integer: 'number',
68
+ bigint: 'number',
69
+ 'double precision': 'number',
70
+ 'timestamp without time zone': 'timestamp',
71
+ oid: 'string',
72
+ boolean: 'boolean',
73
73
  // ARRAY: "string",
74
- "timestamp with time zone": "timestamp",
75
- "timestamp": "timestamp",
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",
87
- "uuid": "string"
74
+ 'timestamp with time zone': 'timestamp',
75
+ timestamp: 'timestamp',
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',
87
+ uuid: 'string',
88
88
  };
89
89
  const DEFAULT_PAGE_SIZE = 1000;
90
90
  const SCHEMA_PAGE_SIZE = 1000;
@@ -113,7 +113,7 @@ class PostgresConnection {
113
113
  }
114
114
  }
115
115
  get dialectName() {
116
- return "postgres";
116
+ return 'postgres';
117
117
  }
118
118
  isPool() {
119
119
  return false;
@@ -132,12 +132,12 @@ class PostgresConnection {
132
132
  if (!inCache) {
133
133
  try {
134
134
  inCache = {
135
- "schema": await this.getTableSchema(tableURL)
135
+ schema: await this.getTableSchema(tableURL),
136
136
  };
137
137
  this.schemaCache.set(tableURL, inCache);
138
138
  }
139
139
  catch (error) {
140
- inCache = { "error": error.message };
140
+ inCache = { error: error.message };
141
141
  }
142
142
  }
143
143
  if (inCache.schema !== undefined) {
@@ -155,11 +155,11 @@ class PostgresConnection {
155
155
  if (!inCache) {
156
156
  try {
157
157
  inCache = {
158
- "structDef": await this.getSQLBlockSchema(sqlRef)
158
+ structDef: await this.getSQLBlockSchema(sqlRef),
159
159
  };
160
160
  }
161
161
  catch (error) {
162
- inCache = { "error": error.message };
162
+ inCache = { error: error.message };
163
163
  }
164
164
  this.sqlSchemaCache.set(key, inCache);
165
165
  }
@@ -168,11 +168,11 @@ class PostgresConnection {
168
168
  async getClient() {
169
169
  const config = await this.readConfig();
170
170
  return new pg_1.Client({
171
- "user": config.username,
172
- "password": config.password,
173
- "database": config.databaseName,
174
- "port": config.port,
175
- "host": config.host
171
+ user: config.username,
172
+ password: config.password,
173
+ database: config.databaseName,
174
+ port: config.port,
175
+ host: config.host,
176
176
  });
177
177
  }
178
178
  async runPostgresQuery(sqlCommand, _pageSize, _rowIndex, deJSON) {
@@ -189,27 +189,27 @@ class PostgresConnection {
189
189
  }
190
190
  await client.end();
191
191
  return {
192
- "rows": result.rows,
193
- "totalRows": result.rows.length
192
+ rows: result.rows,
193
+ totalRows: result.rows.length,
194
194
  };
195
195
  }
196
196
  async getSQLBlockSchema(sqlRef) {
197
197
  const structDef = {
198
- "type": "struct",
199
- "dialect": "postgres",
200
- "name": sqlRef.name,
201
- "structSource": {
202
- "type": "sql",
203
- "method": "subquery",
204
- "sqlBlock": sqlRef
198
+ type: 'struct',
199
+ dialect: 'postgres',
200
+ name: sqlRef.name,
201
+ structSource: {
202
+ type: 'sql',
203
+ method: 'subquery',
204
+ sqlBlock: sqlRef,
205
205
  },
206
- "structRelationship": {
207
- "type": "basetable",
208
- "connectionName": this.name
206
+ structRelationship: {
207
+ type: 'basetable',
208
+ connectionName: this.name,
209
209
  },
210
- "fields": []
210
+ fields: [],
211
211
  };
212
- const tempTableName = `tmp${(0, crypto_1.randomUUID)()}`.replace(/-/g, "");
212
+ const tempTableName = `tmp${(0, crypto_1.randomUUID)()}`.replace(/-/g, '');
213
213
  const infoQuery = `
214
214
  drop table if exists ${tempTableName};
215
215
  create temp table ${tempTableName} as SELECT * FROM (
@@ -227,35 +227,35 @@ class PostgresConnection {
227
227
  async schemaFromQuery(infoQuery, structDef) {
228
228
  const result = await this.runPostgresQuery(infoQuery, SCHEMA_PAGE_SIZE, 0, false);
229
229
  for (const row of result.rows) {
230
- const postgresDataType = row["data_type"];
230
+ const postgresDataType = row['data_type'];
231
231
  let s = structDef;
232
232
  let malloyType = postgresToMalloyTypes[postgresDataType];
233
- let name = row["column_name"];
234
- if (postgresDataType === "ARRAY") {
235
- malloyType = postgresToMalloyTypes[row["element_type"]];
233
+ let name = row['column_name'];
234
+ if (postgresDataType === 'ARRAY') {
235
+ malloyType = postgresToMalloyTypes[row['element_type']];
236
236
  s = {
237
- "type": "struct",
238
- "name": row["column_name"],
239
- "dialect": this.dialectName,
240
- "structRelationship": {
241
- "type": "nested",
242
- "field": name,
243
- "isArray": true
237
+ type: 'struct',
238
+ name: row['column_name'],
239
+ dialect: this.dialectName,
240
+ structRelationship: {
241
+ type: 'nested',
242
+ field: name,
243
+ isArray: true,
244
244
  },
245
- "structSource": { "type": "nested" },
246
- "fields": []
245
+ structSource: { type: 'nested' },
246
+ fields: [],
247
247
  };
248
248
  structDef.fields.push(s);
249
- name = "value";
249
+ name = 'value';
250
250
  }
251
251
  if (malloyType) {
252
- s.fields.push({ "type": malloyType, name });
252
+ s.fields.push({ type: malloyType, name });
253
253
  }
254
254
  else {
255
255
  s.fields.push({
256
- "type": "unsupported",
257
- "rawType": postgresDataType.toLowerCase(),
258
- name
256
+ type: 'unsupported',
257
+ rawType: postgresDataType.toLowerCase(),
258
+ name,
259
259
  });
260
260
  }
261
261
  }
@@ -263,19 +263,19 @@ class PostgresConnection {
263
263
  async getTableSchema(tableURL) {
264
264
  const { tablePath } = (0, malloy_1.parseTableURI)(tableURL);
265
265
  const structDef = {
266
- "type": "struct",
267
- "name": tableURL,
268
- "dialect": "postgres",
269
- "structSource": { "type": "table", tablePath },
270
- "structRelationship": {
271
- "type": "basetable",
272
- "connectionName": this.name
266
+ type: 'struct',
267
+ name: tableURL,
268
+ dialect: 'postgres',
269
+ structSource: { type: 'table', tablePath },
270
+ structRelationship: {
271
+ type: 'basetable',
272
+ connectionName: this.name,
273
273
  },
274
- "fields": []
274
+ fields: [],
275
275
  };
276
- const [schema, table] = tablePath.split(".");
276
+ const [schema, table] = tablePath.split('.');
277
277
  if (table === undefined) {
278
- throw new Error("Default schema not yet supported in Postgres");
278
+ throw new Error('Default schema not yet supported in Postgres');
279
279
  }
280
280
  const infoQuery = `
281
281
  SELECT column_name, c.data_type, e.data_type as element_type
@@ -294,7 +294,7 @@ class PostgresConnection {
294
294
  return queryData.rows;
295
295
  }
296
296
  async test() {
297
- await this.executeSQLRaw("SELECT 1");
297
+ await this.executeSQLRaw('SELECT 1');
298
298
  }
299
299
  async runSQL(sql, { rowLimit } = {}, rowIndex = 0) {
300
300
  var _a;
@@ -318,7 +318,7 @@ class PostgresConnection {
318
318
  await client.end();
319
319
  }
320
320
  async manifestTemporaryTable(sqlCommand) {
321
- const hash = crypto.createHash("md5").update(sqlCommand).digest("hex");
321
+ const hash = crypto.createHash('md5').update(sqlCommand).digest('hex');
322
322
  const tableName = `tt${hash}`;
323
323
  const cmd = `CREATE TEMPORARY TABLE IF NOT EXISTS ${tableName} AS (${sqlCommand});`;
324
324
  // console.log(cmd);
@@ -352,8 +352,8 @@ class PooledPostgresConnection extends PostgresConnection {
352
352
  }
353
353
  }
354
354
  return {
355
- "rows": result.rows,
356
- "totalRows": result.rows.length
355
+ rows: result.rows,
356
+ totalRows: result.rows.length,
357
357
  };
358
358
  }
359
359
  async getClientFromPool() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/db-postgres",
3
- "version": "0.0.24-dev230224214106",
3
+ "version": "0.0.24-dev230301165401",
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.24-dev230224214106",
22
+ "@malloydata/malloy": "^0.0.24-dev230301165401",
23
23
  "@types/pg": "^8.6.1",
24
24
  "pg": "^8.7.1",
25
25
  "pg-query-stream": "4.2.3"