@e-mc/db 0.0.4 → 0.2.0

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.
Files changed (2) hide show
  1. package/index.js +12 -12
  2. package/package.json +4 -3
package/index.js CHANGED
@@ -5,8 +5,8 @@ const types_1 = require("../types");
5
5
  const core_1 = require("../core");
6
6
  const request_1 = require("../request");
7
7
  const util_1 = require("./util");
8
- const DB_CLIENT = {};
9
- const POOL_CONFIG = {};
8
+ const DB_CLIENT = new Map();
9
+ const POOL_CONFIG = new Map();
10
10
  function sanitizePoolConfig(value) {
11
11
  value.min ?? (value.min = -1);
12
12
  value.max ?? (value.max = -1);
@@ -33,14 +33,13 @@ class Db extends core_1.ClientDb {
33
33
  static async purgeMemory(percent = 1, limit = 0, parent) {
34
34
  let result = 0;
35
35
  if (percent > 0 && percent <= 1) {
36
- for (const name in DB_CLIENT) {
37
- const client = DB_CLIENT[name];
38
- const { purge } = POOL_CONFIG[name];
39
- if (purge > 0) {
36
+ for (const [name, client] of DB_CLIENT) {
37
+ const config = POOL_CONFIG.get(name);
38
+ if (config && config.purge > 0) {
40
39
  const checkTimeout = client.checkTimeout?.bind(client);
41
40
  if (checkTimeout) {
42
41
  try {
43
- result += await checkTimeout(purge, limit);
42
+ result += await checkTimeout(config.purge, limit);
44
43
  }
45
44
  catch {
46
45
  }
@@ -54,12 +53,12 @@ class Db extends core_1.ClientDb {
54
53
  for (const name in value) {
55
54
  const source = value[name];
56
55
  if ((0, types_1.isPlainObject)(source)) {
57
- POOL_CONFIG[name] = sanitizePoolConfig(source);
56
+ POOL_CONFIG.set(name, sanitizePoolConfig(source));
58
57
  }
59
58
  }
60
59
  }
61
60
  static getPoolConfig(source) {
62
- return POOL_CONFIG[source];
61
+ return POOL_CONFIG.get(source);
63
62
  }
64
63
  setCredential(item) {
65
64
  try {
@@ -270,15 +269,16 @@ class Db extends core_1.ClientDb {
270
269
  return util_1.SQL_COMMAND;
271
270
  }
272
271
  getClient(source) {
273
- let client;
274
- if (client = DB_CLIENT[source]) {
272
+ let client = DB_CLIENT.get(source);
273
+ if (client) {
275
274
  return client;
276
275
  }
277
276
  try {
278
277
  client = require(this.resolveSource(source));
279
278
  if (client?.DB_SOURCE_CLIENT) {
280
279
  client.DB_SOURCE_NAME = source;
281
- return DB_CLIENT[source] = client;
280
+ DB_CLIENT.set(source, client);
281
+ return client;
282
282
  }
283
283
  }
284
284
  catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/db",
3
- "version": "0.0.4",
3
+ "version": "0.2.0",
4
4
  "description": "DB modules for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,7 +20,8 @@
20
20
  "license": "BSD 3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.0.4",
24
- "@e-mc/request": "0.0.4"
23
+ "@e-mc/core": "0.2.0",
24
+ "@e-mc/request": "0.2.0",
25
+ "@e-mc/types": "0.2.0"
25
26
  }
26
27
  }