@pi-r/postgres 0.6.6 → 0.7.0

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/README.md CHANGED
@@ -1,10 +1,7 @@
1
- # @pi-r/postgres
1
+ ### @pi-r/postgres
2
2
 
3
- ## Documentation
3
+ https://e-mc.readthedocs.io/en/latest/db/postgres.html
4
4
 
5
- - [E-mc](https://e-mc.readthedocs.io/en/latest/db/postgres.html)
6
- - [squared](https://squared.readthedocs.io)
7
-
8
- ## LICENSE
5
+ ### LICENSE
9
6
 
10
7
  MIT
package/client/index.js CHANGED
@@ -30,7 +30,7 @@ function removePoolProperties(credential) {
30
30
  for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
31
31
  const attr = POOL_UNUSED[i];
32
32
  if (attr in credential) {
33
- result || (result = { ...credential });
33
+ result ||= { ...credential };
34
34
  if (attr === 'ssl' && (0, types_1.isObject)(result[attr])) {
35
35
  result[attr] = true;
36
36
  }
@@ -51,14 +51,14 @@ function fromConnectionString(credential, uri) {
51
51
  credential.user = user;
52
52
  credential.password = password;
53
53
  }
54
- credential.host || (credential.host = host);
54
+ credential.host ||= host;
55
55
  if (port) {
56
- credential.port || (credential.port = parseInt(port));
56
+ credential.port ||= parseInt(port);
57
57
  }
58
- credential.database || (credential.database = database);
59
- credential.application_name || (credential.application_name = application_name);
58
+ credential.database ||= database;
59
+ credential.application_name ||= application_name;
60
60
  if (ssl) {
61
- credential.ssl ?? (credential.ssl = (0, types_1.isPlainObject)(ssl) ? ssl : true);
61
+ credential.ssl ??= (0, types_1.isPlainObject)(ssl) ? ssl : true;
62
62
  }
63
63
  return credential;
64
64
  }
@@ -73,8 +73,8 @@ function getPoolKey(credential) {
73
73
  }
74
74
  function setAuthentication(credential) {
75
75
  const auth = (0, util_1.parseServerAuth)(credential);
76
- credential.host || (credential.host = auth.hostname);
77
- credential.user || (credential.user = auth.username);
76
+ credential.host ||= auth.hostname;
77
+ credential.user ||= auth.username;
78
78
  if ((0, types_1.isString)(credential.connectionString)) {
79
79
  fromConnectionString(credential, credential.connectionString);
80
80
  }
@@ -131,16 +131,16 @@ function setCredential(item) {
131
131
  if (config) {
132
132
  const { min, max, idle, timeout } = config;
133
133
  if (min >= 0) {
134
- credential.min ?? (credential.min = min);
134
+ credential.min ??= min;
135
135
  }
136
136
  if (max > 0) {
137
- credential.max ?? (credential.max = max);
137
+ credential.max ??= max;
138
138
  }
139
139
  if (idle > 0) {
140
- credential.idleTimeoutMillis ?? (credential.idleTimeoutMillis = idle);
140
+ credential.idleTimeoutMillis ??= idle;
141
141
  }
142
142
  if (timeout > 0) {
143
- credential.connectionTimeoutMillis ?? (credential.connectionTimeoutMillis = timeout);
143
+ credential.connectionTimeoutMillis ??= timeout;
144
144
  }
145
145
  }
146
146
  const poolKey = getPoolKey(credential);
@@ -178,7 +178,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
178
178
  parallel = !batch.some(item => item.parallel === false);
179
179
  }
180
180
  if (!parallel) {
181
- outResult || (outResult = new Array(length));
181
+ outResult ||= new Array(length);
182
182
  }
183
183
  const caching = this.hasCache("postgres", sessionKey);
184
184
  const tasks = new Array(length);
@@ -261,7 +261,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
261
261
  continue;
262
262
  }
263
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;
264
+ const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("postgres", 'options', credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
265
265
  const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
266
266
  let queryString = '';
267
267
  if (caching && ignoreCache !== true) {
@@ -319,7 +319,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
319
319
  }
320
320
  rows.push(row);
321
321
  })
322
- .on('error', err => error || (error = err))
322
+ .on('error', err => error ||= err)
323
323
  .on('close', () => {
324
324
  if (error && this.handleFail(error, item, { errorQuery, commandType })) {
325
325
  reject(error);
@@ -358,8 +358,16 @@ async function executeBatchQuery(batch, options = '', outResult) {
358
358
  }
359
359
  return this.processRows(batch, tasks, {
360
360
  disconnect: () => {
361
- clients.forEach(item => item.end(err => err && this.writeFail(["Unable to close connnection", "postgres"], err, { type: 65536, fatal: false })));
362
- pools.forEach(item => item.release());
361
+ clients.forEach(item => {
362
+ item.end(err => {
363
+ if (err) {
364
+ this.writeFail(["Unable to close connnection", "postgres"], err, { type: 65536, fatal: false });
365
+ }
366
+ });
367
+ });
368
+ pools.forEach(item => {
369
+ item.release();
370
+ });
363
371
  },
364
372
  parallel
365
373
  }, outResult);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/postgres",
3
- "version": "0.6.6",
3
+ "version": "0.7.0",
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.7",
25
- "@e-mc/types": "^0.8.7",
24
+ "@e-mc/db": "^0.9.0",
25
+ "@e-mc/types": "^0.9.0",
26
26
  "pg": "^8.11.5",
27
27
  "pg-connection-string": "^2.6.4",
28
28
  "pg-query-stream": "^4.5.5"
package/types/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
5
5
  // @ts-ignore
6
6
  import type { PoolConfig, QueryArrayConfig } from 'pg';
7
7
 
8
- export interface PostgresDataSource<T = unknown[]> extends DbDataSource<string | QueryArrayConfig, unknown, unknown, string | PostgresCredential, string>, ExecuteAction<T> {
8
+ export interface PostgresDataSource<T = unknown[]> extends DbDataSource<string | QueryArrayConfig, unknown, unknown, PostgresCredential, string>, ExecuteAction<T> {
9
9
  source: "postgres";
10
10
  }
11
11