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