@pi-r/postgres 0.2.2 → 0.3.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/client/index.js +23 -8
- package/package.json +4 -4
package/client/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DB_SOURCE_TYPE = exports.DB_SOURCE_CLIENT = exports.checkTimeout = exports.executeBatchQuery = exports.executeQuery = exports.setCredential = exports.setAuthentication = void 0;
|
|
4
|
+
const postgres = require("pg");
|
|
4
5
|
const util_1 = require("@e-mc/db/util");
|
|
5
6
|
const types_1 = require("@e-mc/types");
|
|
6
7
|
const Db = require("@e-mc/db");
|
|
@@ -20,11 +21,27 @@ class PostgresPool extends DbPool {
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
const POOL_STATE = {};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const POOL_UNUSED = ['ssl', 'keepAlive', 'statement_timeout', 'query_timeout', 'keepAliveInitialDelayMillis', 'idle_in_transaction_session_timeout', 'connectionTimeoutMillis', 'max', 'min', 'idleTimeoutMillis', 'log', 'allowExitOnIdle', 'maxUses'];
|
|
25
|
+
function removePoolProperties(credential) {
|
|
26
|
+
if (!credential.uuidKey) {
|
|
27
|
+
let result;
|
|
28
|
+
for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
|
|
29
|
+
const attr = POOL_UNUSED[i];
|
|
30
|
+
if (attr in credential) {
|
|
31
|
+
result || (result = { ...credential });
|
|
32
|
+
if (attr === 'ssl' && (0, types_1.isObject)(result[attr])) {
|
|
33
|
+
result[attr] = true;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
delete result[attr];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (result) {
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
26
43
|
}
|
|
27
|
-
return
|
|
44
|
+
return credential;
|
|
28
45
|
}
|
|
29
46
|
const getPoolKey = (credential) => (credential.host || '') + '_' + (credential.port || '5432') + (credential.user || '') + '_' + (credential.password || '') + '_' + (credential.database || '') + '_' + (credential.connectionString || '');
|
|
30
47
|
function setAuthentication(credential) {
|
|
@@ -69,7 +86,6 @@ function setCredential(item) {
|
|
|
69
86
|
}
|
|
70
87
|
const poolKey = getPoolKey(credential);
|
|
71
88
|
if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
|
|
72
|
-
const { Pool } = require("pg" /* STRINGS.PACKAGE_NAME */);
|
|
73
89
|
const config = this.getPoolConfig("postgres" /* STRINGS.MODULE_NAME */, password);
|
|
74
90
|
if (config) {
|
|
75
91
|
const { min, max, idle } = config;
|
|
@@ -83,7 +99,7 @@ function setCredential(item) {
|
|
|
83
99
|
credential.idleTimeoutMillis ?? (credential.idleTimeoutMillis = idle);
|
|
84
100
|
}
|
|
85
101
|
}
|
|
86
|
-
new PostgresPool(new Pool(credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
102
|
+
new PostgresPool(new postgres.Pool(credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
87
103
|
}
|
|
88
104
|
else {
|
|
89
105
|
pool.add(item);
|
|
@@ -103,7 +119,6 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
103
119
|
if (length === 0) {
|
|
104
120
|
return [];
|
|
105
121
|
}
|
|
106
|
-
const db = require("pg" /* STRINGS.PACKAGE_NAME */);
|
|
107
122
|
let parallel, connectOnce, errorQuery, sessionKey, outCacheMiss;
|
|
108
123
|
if ((0, types_1.isPlainObject)(options)) {
|
|
109
124
|
({ parallel, connectOnce, errorQuery, sessionKey, outCacheMiss } = options);
|
|
@@ -167,7 +182,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
167
182
|
}
|
|
168
183
|
}
|
|
169
184
|
if (!client) {
|
|
170
|
-
clients.push(client = new
|
|
185
|
+
clients.push(client = new postgres.Client((postgresCredential || credential)));
|
|
171
186
|
await client.connect();
|
|
172
187
|
}
|
|
173
188
|
if (connectOnce) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/postgres",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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.
|
|
25
|
-
"@e-mc/types": "^0.
|
|
26
|
-
"pg": "^8.11.
|
|
24
|
+
"@e-mc/db": "^0.6.0",
|
|
25
|
+
"@e-mc/types": "^0.6.0",
|
|
26
|
+
"pg": "^8.11.2"
|
|
27
27
|
}
|
|
28
28
|
}
|