@pi-r/postgres 0.3.0 → 0.3.2
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 +1 -1
- package/README.md +4 -2
- package/client/index.d.ts +2 -1
- package/client/index.js +11 -11
- package/package.json +5 -5
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Studio Trigger
|
|
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
package/client/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { IDb } from '@e-mc/types/lib';
|
|
2
|
-
import type { PostgresCredential, PostgresDataSource } from '@e-mc/types/lib/db';
|
|
3
2
|
|
|
4
3
|
import type { IDbSourceClient } from '@e-mc/db/types';
|
|
5
4
|
|
|
5
|
+
import type { PostgresCredential, PostgresDataSource } from '../types';
|
|
6
|
+
|
|
6
7
|
declare const Postgres: IDbSourceClient<PostgresDataSource> & {
|
|
7
8
|
setAuthentication(this: IDb, credential: PostgresCredential): void;
|
|
8
9
|
};
|
package/client/index.js
CHANGED
|
@@ -71,7 +71,7 @@ function setCredential(item) {
|
|
|
71
71
|
errors.push('user');
|
|
72
72
|
}
|
|
73
73
|
if (errors.length) {
|
|
74
|
-
throw (0, types_1.errorMessage)("postgres"
|
|
74
|
+
throw (0, types_1.errorMessage)("postgres", 'Not defined - ' + errors.join(' | '));
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
const usePool = item.usePool;
|
|
@@ -86,7 +86,7 @@ function setCredential(item) {
|
|
|
86
86
|
}
|
|
87
87
|
const poolKey = getPoolKey(credential);
|
|
88
88
|
if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
|
|
89
|
-
const config = this.getPoolConfig("postgres"
|
|
89
|
+
const config = this.getPoolConfig("postgres", password);
|
|
90
90
|
if (config) {
|
|
91
91
|
const { min, max, idle } = config;
|
|
92
92
|
if (min >= 0) {
|
|
@@ -139,17 +139,17 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
139
139
|
if (!parallel) {
|
|
140
140
|
outResult || (outResult = new Array(length));
|
|
141
141
|
}
|
|
142
|
-
const caching = this.hasCache("postgres"
|
|
142
|
+
const caching = this.hasCache("postgres", sessionKey);
|
|
143
143
|
const tasks = new Array(length);
|
|
144
144
|
const clients = [];
|
|
145
145
|
const pools = [];
|
|
146
146
|
let postgresPool, postgresClient, postgresCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
|
|
147
147
|
const getConnection = async (item, credential) => {
|
|
148
|
-
item.transactionState = 64
|
|
148
|
+
item.transactionState = 64;
|
|
149
149
|
let client;
|
|
150
150
|
if (postgresPool) {
|
|
151
151
|
pools.push(client = await postgresPool.getConnection());
|
|
152
|
-
item.transactionState &= ~64
|
|
152
|
+
item.transactionState &= ~64;
|
|
153
153
|
return client;
|
|
154
154
|
}
|
|
155
155
|
const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
|
|
@@ -191,14 +191,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
191
191
|
}
|
|
192
192
|
postgresCredential = credential;
|
|
193
193
|
}
|
|
194
|
-
item.transactionState &= ~64
|
|
194
|
+
item.transactionState &= ~64;
|
|
195
195
|
return client;
|
|
196
196
|
};
|
|
197
197
|
for (let i = 0; i < length; ++i) {
|
|
198
198
|
const item = batch[i];
|
|
199
199
|
const { source, query, params, ignoreCache } = item;
|
|
200
200
|
let credential = postgresCredential || onceCredential, error;
|
|
201
|
-
if (!credential && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials"
|
|
201
|
+
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"))) {
|
|
202
202
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
203
203
|
if (!parallel) {
|
|
204
204
|
tasks.length = 0;
|
|
@@ -214,7 +214,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
214
214
|
}
|
|
215
215
|
continue;
|
|
216
216
|
}
|
|
217
|
-
item.transactionState = 1
|
|
217
|
+
item.transactionState = 1;
|
|
218
218
|
const renewCache = ignoreCache === 0;
|
|
219
219
|
const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
|
|
220
220
|
let queryString = '';
|
|
@@ -229,7 +229,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
229
229
|
else {
|
|
230
230
|
outResult[i] = result;
|
|
231
231
|
}
|
|
232
|
-
this.add(item, 4
|
|
232
|
+
this.add(item, 4 | 128);
|
|
233
233
|
continue;
|
|
234
234
|
}
|
|
235
235
|
if (!ignoreCache && outCacheMiss) {
|
|
@@ -256,7 +256,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
256
256
|
}
|
|
257
257
|
commandType = this.commandType.SELECT;
|
|
258
258
|
const { rows, command } = await client.query(query, params);
|
|
259
|
-
this.add(item, 4
|
|
259
|
+
this.add(item, 4);
|
|
260
260
|
resolve(rows.length || command === 'SELECT' ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
|
|
261
261
|
}
|
|
262
262
|
catch (err) {
|
|
@@ -280,7 +280,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
280
280
|
}
|
|
281
281
|
return this.processRows(batch, tasks, {
|
|
282
282
|
disconnect: () => {
|
|
283
|
-
clients.forEach(item => item.end(err => err && this.writeFail(["Unable to close connnection"
|
|
283
|
+
clients.forEach(item => item.end(err => err && this.writeFail(["Unable to close connnection", "postgres"], err, { type: 65536, fatal: false })));
|
|
284
284
|
pools.forEach(item => item.release());
|
|
285
285
|
},
|
|
286
286
|
parallel
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/postgres",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "PostgreSQL client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
13
13
|
"directory": "src/db/postgres"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -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.6.
|
|
25
|
-
"@e-mc/types": "^0.6.
|
|
26
|
-
"pg": "^8.11.
|
|
24
|
+
"@e-mc/db": "^0.6.1",
|
|
25
|
+
"@e-mc/types": "^0.6.1",
|
|
26
|
+
"pg": "^8.11.3"
|
|
27
27
|
}
|
|
28
28
|
}
|