@pi-r/postgres 0.7.2 → 0.7.4
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 +6 -6
- package/client/pool.js +55 -0
- package/package.json +30 -30
- package/types/index.d.ts +11 -11
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
### @pi-r/postgres
|
|
2
|
-
|
|
3
|
-
https://e-mc.readthedocs.io/en/latest/db/postgres.html
|
|
4
|
-
|
|
5
|
-
### LICENSE
|
|
6
|
-
|
|
1
|
+
### @pi-r/postgres
|
|
2
|
+
|
|
3
|
+
https://e-mc.readthedocs.io/en/latest/db/postgres.html
|
|
4
|
+
|
|
5
|
+
### LICENSE
|
|
6
|
+
|
|
7
7
|
MIT
|
package/client/pool.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const types_1 = require("@e-mc/types");
|
|
3
|
+
const DbPool = require('@e-mc/db/pool');
|
|
4
|
+
const POOL_ACTIVE = new WeakSet();
|
|
5
|
+
class PostgresPool extends DbPool {
|
|
6
|
+
static asString(credential) {
|
|
7
|
+
if (credential.host && credential.user) {
|
|
8
|
+
return JSON.stringify(this.removeUUIDKey(credential));
|
|
9
|
+
}
|
|
10
|
+
return super.asString(credential);
|
|
11
|
+
}
|
|
12
|
+
static sanitize(credential) {
|
|
13
|
+
if (!POOL_ACTIVE.has(credential) || credential.uuidKey) {
|
|
14
|
+
return credential;
|
|
15
|
+
}
|
|
16
|
+
const ssl = credential.ssl;
|
|
17
|
+
let result = super.sanitize(credential);
|
|
18
|
+
if ((0, types_1.isObject)(ssl)) {
|
|
19
|
+
if (result === credential) {
|
|
20
|
+
result = { ...credential };
|
|
21
|
+
}
|
|
22
|
+
const cert = ssl.cert;
|
|
23
|
+
if ((0, types_1.isString)(cert)) {
|
|
24
|
+
result.ssl = { cert };
|
|
25
|
+
}
|
|
26
|
+
else if (Buffer.isBuffer(cert)) {
|
|
27
|
+
result.ssl = { cert: cert.toString('utf-8') };
|
|
28
|
+
}
|
|
29
|
+
else if ((0, types_1.isArray)(cert)) {
|
|
30
|
+
result.ssl = { cert: cert.reduce((a, b) => a + (Buffer.isBuffer(b) ? b.toString('utf-8') : b), '') };
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
result.ssl = { cert: "Unknown" };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
async getConnection(credential) {
|
|
39
|
+
if (credential) {
|
|
40
|
+
POOL_ACTIVE.add(credential);
|
|
41
|
+
}
|
|
42
|
+
return this.client.connect();
|
|
43
|
+
}
|
|
44
|
+
async close() {
|
|
45
|
+
return this.client.end();
|
|
46
|
+
}
|
|
47
|
+
isEmpty() {
|
|
48
|
+
return this.closed || this.client.totalCount === 0 && this.client.waitingCount === 0;
|
|
49
|
+
}
|
|
50
|
+
get closed() {
|
|
51
|
+
return this.client.ended;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
PostgresPool.CACHE_UNUSED = ['keepAlive', 'statement_timeout', 'query_timeout', 'keepAliveInitialDelayMillis', 'idle_in_transaction_session_timeout', 'connectionTimeoutMillis', 'max', 'min', 'idleTimeoutMillis', 'log', 'allowExitOnIdle', 'maxUses'];
|
|
55
|
+
module.exports = PostgresPool;
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pi-r/postgres",
|
|
3
|
-
"version": "0.7.
|
|
4
|
-
"description": "PostgreSQL client driver for E-mc.",
|
|
5
|
-
"main": "client/index.js",
|
|
6
|
-
"types": "client/index.d.ts",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
13
|
-
"directory": "src/db/postgres"
|
|
14
|
-
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"squared",
|
|
17
|
-
"e-mc",
|
|
18
|
-
"squared-functions"
|
|
19
|
-
],
|
|
20
|
-
"author": "An Pham <anpham6@gmail.com>",
|
|
21
|
-
"license": "MIT",
|
|
22
|
-
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"@e-mc/db": "^0.9.
|
|
25
|
-
"@e-mc/types": "^0.9.
|
|
26
|
-
"pg": "^8.
|
|
27
|
-
"pg-connection-string": "^2.
|
|
28
|
-
"pg-query-stream": "^4.
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-r/postgres",
|
|
3
|
+
"version": "0.7.4",
|
|
4
|
+
"description": "PostgreSQL client driver for E-mc.",
|
|
5
|
+
"main": "client/index.js",
|
|
6
|
+
"types": "client/index.d.ts",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
13
|
+
"directory": "src/db/postgres"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"squared",
|
|
17
|
+
"e-mc",
|
|
18
|
+
"squared-functions"
|
|
19
|
+
],
|
|
20
|
+
"author": "An Pham <anpham6@gmail.com>",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@e-mc/db": "^0.9.12",
|
|
25
|
+
"@e-mc/types": "^0.9.12",
|
|
26
|
+
"pg": "^8.13.0",
|
|
27
|
+
"pg-connection-string": "^2.7.0",
|
|
28
|
+
"pg-query-stream": "^4.7.0"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { DbDataSource } from '@e-mc/types/lib/squared';
|
|
2
|
-
|
|
3
|
-
import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
4
|
-
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import type { PoolConfig, QueryArrayConfig } from 'pg';
|
|
7
|
-
|
|
8
|
-
export interface PostgresDataSource<T = unknown[]> extends DbDataSource<string | QueryArrayConfig, unknown, unknown, PostgresCredential, string>, ExecuteAction<T> {
|
|
9
|
-
source: "postgres";
|
|
10
|
-
}
|
|
11
|
-
|
|
1
|
+
import type { DbDataSource } from '@e-mc/types/lib/squared';
|
|
2
|
+
|
|
3
|
+
import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
4
|
+
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import type { PoolConfig, QueryArrayConfig } from 'pg';
|
|
7
|
+
|
|
8
|
+
export interface PostgresDataSource<T = unknown[]> extends DbDataSource<string | QueryArrayConfig, unknown, unknown, PostgresCredential, string>, ExecuteAction<T> {
|
|
9
|
+
source: "postgres";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
12
|
export interface PostgresCredential extends Omit<ServerAuth, "password">, PoolConfig {}
|