@pi-r/postgres 0.6.4 → 0.6.5

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
@@ -104,7 +104,7 @@ function setCredential(item) {
104
104
  errors.push('user');
105
105
  }
106
106
  if (errors.length) {
107
- throw (0, types_1.errorMessage)("postgres" /* STRINGS.MODULE_NAME */, 'Not defined - ' + errors.join(' | '));
107
+ throw (0, types_1.errorMessage)("postgres", 'Not defined - ' + errors.join(' | '));
108
108
  }
109
109
  }
110
110
  const usePool = item.usePool;
@@ -128,7 +128,7 @@ function setCredential(item) {
128
128
  return;
129
129
  }
130
130
  }
131
- const config = this.getPoolConfig("postgres" /* STRINGS.MODULE_NAME */, password);
131
+ const config = this.getPoolConfig("postgres", password);
132
132
  if (config) {
133
133
  const { min, max, idle, timeout } = config;
134
134
  if (min >= 0) {
@@ -181,17 +181,17 @@ async function executeBatchQuery(batch, options = '', outResult) {
181
181
  if (!parallel) {
182
182
  outResult || (outResult = new Array(length));
183
183
  }
184
- const caching = this.hasCache("postgres" /* STRINGS.MODULE_NAME */, sessionKey);
184
+ const caching = this.hasCache("postgres", sessionKey);
185
185
  const tasks = new Array(length);
186
186
  const clients = [];
187
187
  const pools = [];
188
188
  let postgresPool, postgresClient, postgresCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
189
189
  const getConnection = async (item, credential) => {
190
- item.transactionState = 64 /* DB_TRANSACTION.AUTH */;
190
+ item.transactionState = 64;
191
191
  let client;
192
192
  if (postgresPool) {
193
193
  pools.push(client = await postgresPool.getConnection());
194
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
194
+ item.transactionState &= ~64;
195
195
  POOL_ACTIVE.add(credential);
196
196
  return client;
197
197
  }
@@ -235,7 +235,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
235
235
  }
236
236
  postgresCredential = credential;
237
237
  }
238
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
238
+ item.transactionState &= ~64;
239
239
  return client;
240
240
  };
241
241
  if (this.host?.username) {
@@ -245,7 +245,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
245
245
  const item = batch[i];
246
246
  const { source, query, params, ignoreCache } = item;
247
247
  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 */))) {
248
+ 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
249
  if (this.handleFail(error, item, { errorQuery })) {
250
250
  if (!parallel) {
251
251
  tasks.length = 0;
@@ -261,8 +261,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
261
261
  }
262
262
  continue;
263
263
  }
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;
264
+ item.transactionState = 1;
265
+ const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("postgres", 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
266
266
  const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
267
267
  let queryString = '';
268
268
  if (caching && ignoreCache !== true) {
@@ -276,7 +276,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
276
276
  else {
277
277
  outResult[i] = result;
278
278
  }
279
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */ | 128 /* DB_TRANSACTION.CACHE */);
279
+ this.add(item, 4 | 128);
280
280
  continue;
281
281
  }
282
282
  if (!ignoreCache && outCacheMiss) {
@@ -326,7 +326,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
326
326
  reject(error);
327
327
  }
328
328
  else {
329
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
329
+ this.add(item, 4);
330
330
  resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows);
331
331
  }
332
332
  })
@@ -334,7 +334,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
334
334
  }
335
335
  else {
336
336
  const { rows, command } = await client.query(query, params);
337
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
337
+ this.add(item, 4);
338
338
  resolve(rows.length || command === 'SELECT' ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
339
339
  }
340
340
  }
@@ -359,7 +359,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
359
359
  }
360
360
  return this.processRows(batch, tasks, {
361
361
  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 })));
362
+ clients.forEach(item => item.end(err => err && this.writeFail(["Unable to close connnection", "postgres"], err, { type: 65536, fatal: false })));
363
363
  pools.forEach(item => item.release());
364
364
  },
365
365
  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.5",
4
4
  "description": "PostgreSQL client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -21,8 +21,8 @@
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",
24
+ "@e-mc/db": "^0.8.6",
25
+ "@e-mc/types": "^0.8.6",
26
26
  "pg": "^8.11.3",
27
27
  "pg-connection-string": "^2.6.2",
28
28
  "pg-query-stream": "^4.5.3"
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> {