@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 +1 -1
- package/README.md +6 -3
- package/client/index.js +13 -13
- package/package.json +3 -3
- package/types/index.d.ts +1 -0
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
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
|
-
|
|
1
|
+
# @pi-r/postgres
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Documentation
|
|
4
4
|
|
|
5
|
-
|
|
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"
|
|
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"
|
|
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"
|
|
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
|
|
190
|
+
item.transactionState = 64;
|
|
191
191
|
let client;
|
|
192
192
|
if (postgresPool) {
|
|
193
193
|
pools.push(client = await postgresPool.getConnection());
|
|
194
|
-
item.transactionState &= ~64
|
|
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
|
|
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"
|
|
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
|
|
265
|
-
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("postgres"
|
|
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
|
|
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
|
|
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
|
|
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"
|
|
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.
|
|
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.
|
|
25
|
-
"@e-mc/types": "^0.8.
|
|
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> {
|