@pi-r/postgres 0.6.4 → 0.6.6

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2024 An Pham
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/README.md CHANGED
@@ -1,7 +1,10 @@
1
- ### @pi-r/postgres
1
+ # @pi-r/postgres
2
2
 
3
- https://e-mc.readthedocs.io/en/latest/db/postgres.html
3
+ ## Documentation
4
4
 
5
- ### LICENSE
5
+ - [E-mc](https://e-mc.readthedocs.io/en/latest/db/postgres.html)
6
+ - [squared](https://squared.readthedocs.io)
7
+
8
+ ## LICENSE
6
9
 
7
10
  MIT
package/client/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  exports.DB_SOURCE_TYPE = exports.DB_SOURCE_CLIENT = exports.checkTimeout = exports.executeBatchQuery = exports.executeQuery = exports.setCredential = exports.setAuthentication = void 0;
4
3
  const postgres = require("pg");
5
4
  const connectionString = require("pg-connection-string");
@@ -104,7 +103,7 @@ function setCredential(item) {
104
103
  errors.push('user');
105
104
  }
106
105
  if (errors.length) {
107
- throw (0, types_1.errorMessage)("postgres" /* STRINGS.MODULE_NAME */, 'Not defined - ' + errors.join(' | '));
106
+ throw (0, types_1.errorMessage)("postgres", 'Not defined - ' + errors.join(' | '));
108
107
  }
109
108
  }
110
109
  const usePool = item.usePool;
@@ -128,7 +127,7 @@ function setCredential(item) {
128
127
  return;
129
128
  }
130
129
  }
131
- const config = this.getPoolConfig("postgres" /* STRINGS.MODULE_NAME */, password);
130
+ const config = this.getPoolConfig("postgres", password);
132
131
  if (config) {
133
132
  const { min, max, idle, timeout } = config;
134
133
  if (min >= 0) {
@@ -181,17 +180,17 @@ async function executeBatchQuery(batch, options = '', outResult) {
181
180
  if (!parallel) {
182
181
  outResult || (outResult = new Array(length));
183
182
  }
184
- const caching = this.hasCache("postgres" /* STRINGS.MODULE_NAME */, sessionKey);
183
+ const caching = this.hasCache("postgres", sessionKey);
185
184
  const tasks = new Array(length);
186
185
  const clients = [];
187
186
  const pools = [];
188
187
  let postgresPool, postgresClient, postgresCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
189
188
  const getConnection = async (item, credential) => {
190
- item.transactionState = 64 /* DB_TRANSACTION.AUTH */;
189
+ item.transactionState = 64;
191
190
  let client;
192
191
  if (postgresPool) {
193
192
  pools.push(client = await postgresPool.getConnection());
194
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
193
+ item.transactionState &= ~64;
195
194
  POOL_ACTIVE.add(credential);
196
195
  return client;
197
196
  }
@@ -235,7 +234,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
235
234
  }
236
235
  postgresCredential = credential;
237
236
  }
238
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
237
+ item.transactionState &= ~64;
239
238
  return client;
240
239
  };
241
240
  if (this.host?.username) {
@@ -245,7 +244,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
245
244
  const item = batch[i];
246
245
  const { source, query, params, ignoreCache } = item;
247
246
  let credential = postgresCredential || onceCredential, error;
248
- if (!credential && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials" /* ERR_DB.CREDENTIALS */)) || !query && (error = (0, types_1.errorMessage)(source, "Missing database query" /* ERR_DB.QUERY */))) {
247
+ if (!credential && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials")) || !query && (error = (0, types_1.errorMessage)(source, "Missing database query"))) {
249
248
  if (this.handleFail(error, item, { errorQuery })) {
250
249
  if (!parallel) {
251
250
  tasks.length = 0;
@@ -261,8 +260,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
261
260
  }
262
261
  continue;
263
262
  }
264
- item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
265
- const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("postgres" /* STRINGS.MODULE_NAME */, 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
263
+ item.transactionState = 1;
264
+ const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("postgres", 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
266
265
  const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
267
266
  let queryString = '';
268
267
  if (caching && ignoreCache !== true) {
@@ -276,7 +275,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
276
275
  else {
277
276
  outResult[i] = result;
278
277
  }
279
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */ | 128 /* DB_TRANSACTION.CACHE */);
278
+ this.add(item, 4 | 128);
280
279
  continue;
281
280
  }
282
281
  if (!ignoreCache && outCacheMiss) {
@@ -326,7 +325,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
326
325
  reject(error);
327
326
  }
328
327
  else {
329
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
328
+ this.add(item, 4);
330
329
  resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows);
331
330
  }
332
331
  })
@@ -334,7 +333,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
334
333
  }
335
334
  else {
336
335
  const { rows, command } = await client.query(query, params);
337
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
336
+ this.add(item, 4);
338
337
  resolve(rows.length || command === 'SELECT' ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
339
338
  }
340
339
  }
@@ -359,7 +358,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
359
358
  }
360
359
  return this.processRows(batch, tasks, {
361
360
  disconnect: () => {
362
- clients.forEach(item => item.end(err => err && this.writeFail(["Unable to close connnection" /* ERR_DB.CONNECTION_CLOSE */, "postgres" /* STRINGS.MODULE_NAME */], err, { type: 65536 /* LOG_TYPE.DB */, fatal: false })));
361
+ clients.forEach(item => item.end(err => err && this.writeFail(["Unable to close connnection", "postgres"], err, { type: 65536, fatal: false })));
363
362
  pools.forEach(item => item.release());
364
363
  },
365
364
  parallel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/postgres",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "PostgreSQL client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -21,10 +21,10 @@
21
21
  "license": "MIT",
22
22
  "homepage": "https://github.com/anpham6/pi-r#readme",
23
23
  "dependencies": {
24
- "@e-mc/db": "^0.8.4",
25
- "@e-mc/types": "^0.8.4",
26
- "pg": "^8.11.3",
27
- "pg-connection-string": "^2.6.2",
28
- "pg-query-stream": "^4.5.3"
24
+ "@e-mc/db": "^0.8.7",
25
+ "@e-mc/types": "^0.8.7",
26
+ "pg": "^8.11.5",
27
+ "pg-connection-string": "^2.6.4",
28
+ "pg-query-stream": "^4.5.5"
29
29
  }
30
30
  }
package/types/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { DbDataSource } from '@e-mc/types/lib/squared';
2
2
 
3
3
  import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
4
4
 
5
+ // @ts-ignore
5
6
  import type { PoolConfig, QueryArrayConfig } from 'pg';
6
7
 
7
8
  export interface PostgresDataSource<T = unknown[]> extends DbDataSource<string | QueryArrayConfig, unknown, unknown, string | PostgresCredential, string>, ExecuteAction<T> {