@pi-r/postgres 0.6.1 → 0.6.3

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 CHANGED
@@ -1,5 +1,7 @@
1
1
  ### @pi-r/postgres
2
2
 
3
+ https://e-mc.readthedocs.io/en/latest/db/postgres.html
4
+
3
5
  ### LICENSE
4
6
 
5
7
  MIT
package/client/index.js CHANGED
@@ -62,7 +62,15 @@ function fromConnectionString(credential, uri) {
62
62
  }
63
63
  return credential;
64
64
  }
65
- const getPoolKey = (credential) => (credential.host || '') + '_' + (credential.port || '5432') + (credential.user || '') + '_' + (credential.password || '') + '_' + (credential.database || '') + '_' + (credential.connectionString || '');
65
+ function getPoolKey(credential) {
66
+ if (credential.host && credential.user) {
67
+ if ('uuidKey' in credential) {
68
+ credential = { ...credential };
69
+ delete credential.uuidKey;
70
+ }
71
+ return JSON.stringify(credential);
72
+ }
73
+ }
66
74
  function setAuthentication(credential) {
67
75
  const auth = (0, util_1.parseServerAuth)(credential);
68
76
  credential.host || (credential.host = auth.hostname);
@@ -106,18 +114,19 @@ function setCredential(item) {
106
114
  return;
107
115
  }
108
116
  let username, password, pool;
109
- if (typeof usePool === 'string' && (username = credential.user || credential.connectionString && (0, util_1.parseConnectionString)(credential.connectionString)?.username)) {
110
- [password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
111
- if (pool) {
112
- pool.add(item, password);
117
+ if ((0, types_1.isString)(usePool)) {
118
+ if (username = credential.user || credential.connectionString && (0, util_1.parseConnectionString)(credential.connectionString)?.username) {
119
+ [password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
120
+ if (pool) {
121
+ pool.add(item, password);
122
+ return;
123
+ }
124
+ }
125
+ if (!password) {
126
+ item.usePool = '';
113
127
  return;
114
128
  }
115
129
  }
116
- const poolKey = getPoolKey(credential);
117
- if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
118
- pool.add(item);
119
- return;
120
- }
121
130
  const config = this.getPoolConfig("postgres" /* STRINGS.MODULE_NAME */, password);
122
131
  if (config) {
123
132
  const { min, max, idle, timeout } = config;
@@ -134,6 +143,11 @@ function setCredential(item) {
134
143
  credential.connectionTimeoutMillis ?? (credential.connectionTimeoutMillis = timeout);
135
144
  }
136
145
  }
146
+ const poolKey = getPoolKey(credential);
147
+ if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
148
+ pool.add(item);
149
+ return;
150
+ }
137
151
  new PostgresPool(new postgres.Pool(credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
138
152
  }
139
153
  exports.setCredential = setCredential;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/postgres",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
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.8.1",
25
- "@e-mc/types": "^0.8.1",
24
+ "@e-mc/db": "^0.8.3",
25
+ "@e-mc/types": "^0.8.3",
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,7 +2,6 @@ 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
6
5
  import type { PoolConfig, QueryArrayConfig } from 'pg';
7
6
 
8
7
  export interface PostgresDataSource<T = unknown[]> extends DbDataSource<string | QueryArrayConfig, unknown, unknown, string | PostgresCredential, string>, ExecuteAction<T> {