@pi-r/postgres 0.5.0 → 0.5.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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2023 Haruhi Suzumiya
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,5 +1,7 @@
1
- ### @pi-r/postgres
1
+ # @pi-r/postgres
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever
4
+
5
+ ## LICENSE
4
6
 
5
7
  MIT
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" /* STRINGS.MODULE_NAME */, 'Not defined - ' + errors.join(' | '));
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" /* STRINGS.MODULE_NAME */, password);
89
+ const config = this.getPoolConfig("postgres", password);
90
90
  if (config) {
91
91
  const { min, max, idle, timeout } = config;
92
92
  if (min >= 0) {
@@ -142,17 +142,17 @@ async function executeBatchQuery(batch, options = '', outResult) {
142
142
  if (!parallel) {
143
143
  outResult || (outResult = new Array(length));
144
144
  }
145
- const caching = this.hasCache("postgres" /* STRINGS.MODULE_NAME */, sessionKey);
145
+ const caching = this.hasCache("postgres", sessionKey);
146
146
  const tasks = new Array(length);
147
147
  const clients = [];
148
148
  const pools = [];
149
149
  let postgresPool, postgresClient, postgresCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
150
150
  const getConnection = async (item, credential) => {
151
- item.transactionState = 64 /* DB_TRANSACTION.AUTH */;
151
+ item.transactionState = 64;
152
152
  let client;
153
153
  if (postgresPool) {
154
154
  pools.push(client = await postgresPool.getConnection());
155
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
155
+ item.transactionState &= ~64;
156
156
  return client;
157
157
  }
158
158
  const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
@@ -194,14 +194,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
194
194
  }
195
195
  postgresCredential = credential;
196
196
  }
197
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
197
+ item.transactionState &= ~64;
198
198
  return client;
199
199
  };
200
200
  for (let i = 0; i < length; ++i) {
201
201
  const item = batch[i];
202
202
  const { source, query, params, ignoreCache } = item;
203
203
  let credential = postgresCredential || onceCredential, error;
204
- if (!credential && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials" /* ERR_DB.CREDENTIALS */)) || !query && (error = (0, types_1.errorMessage)(source, "Missing database query" /* ERR_DB.QUERY */))) {
204
+ 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"))) {
205
205
  if (this.handleFail(error, item, { errorQuery })) {
206
206
  if (!parallel) {
207
207
  tasks.length = 0;
@@ -217,7 +217,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
217
217
  }
218
218
  continue;
219
219
  }
220
- item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
220
+ item.transactionState = 1;
221
221
  const renewCache = ignoreCache === 0;
222
222
  const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
223
223
  let queryString = '';
@@ -232,7 +232,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
232
232
  else {
233
233
  outResult[i] = result;
234
234
  }
235
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */ | 128 /* DB_TRANSACTION.CACHE */);
235
+ this.add(item, 4 | 128);
236
236
  continue;
237
237
  }
238
238
  if (!ignoreCache && outCacheMiss) {
@@ -259,7 +259,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
259
259
  }
260
260
  commandType = this.commandType.SELECT;
261
261
  const { rows, command } = await client.query(query, params);
262
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
262
+ this.add(item, 4);
263
263
  resolve(rows.length || command === 'SELECT' ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
264
264
  }
265
265
  catch (err) {
@@ -283,7 +283,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
283
283
  }
284
284
  return this.processRows(batch, tasks, {
285
285
  disconnect: () => {
286
- clients.forEach(item => item.end(err => err && this.writeFail(["Unable to close connnection" /* ERR_DB.CONNECTION_CLOSE */, "postgres" /* STRINGS.MODULE_NAME */], err, { type: 65536 /* LOG_TYPE.DB */, fatal: false })));
286
+ clients.forEach(item => item.end(err => err && this.writeFail(["Unable to close connnection", "postgres"], err, { type: 65536, fatal: false })));
287
287
  pools.forEach(item => item.release());
288
288
  },
289
289
  parallel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/postgres",
3
- "version": "0.5.0",
3
+ "version": "0.5.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.7.0",
25
- "@e-mc/types": "^0.7.0",
26
- "pg": "^8.11.3"
24
+ "@e-mc/db": "^0.7.3",
25
+ "@e-mc/types": "^0.7.3",
26
+ "pg": "^8.11.5"
27
27
  }
28
28
  }
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> {