@pi-r/mariadb 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/index.d.ts +10 -10
- package/client/pool.js +56 -0
- package/package.json +28 -28
- package/types/index.d.ts +14 -14
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
### @pi-r/mariadb
|
|
2
|
-
|
|
3
|
-
https://e-mc.readthedocs.io/en/latest/db/mariadb.html
|
|
4
|
-
|
|
5
|
-
### LICENSE
|
|
6
|
-
|
|
1
|
+
### @pi-r/mariadb
|
|
2
|
+
|
|
3
|
+
https://e-mc.readthedocs.io/en/latest/db/mariadb.html
|
|
4
|
+
|
|
5
|
+
### LICENSE
|
|
6
|
+
|
|
7
7
|
MIT
|
package/client/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { IDb } from '@e-mc/types/lib';
|
|
2
|
-
|
|
3
|
-
import type { IDbSourceClient } from '@e-mc/db/types';
|
|
4
|
-
|
|
5
|
-
import type { MariaDBCredential, MariaDBDataSource } from '../types';
|
|
6
|
-
|
|
7
|
-
declare const MariaDB: IDbSourceClient<MariaDBDataSource> & {
|
|
8
|
-
setAuthentication(this: IDb, credential: MariaDBCredential): void;
|
|
9
|
-
};
|
|
10
|
-
|
|
1
|
+
import type { IDb } from '@e-mc/types/lib';
|
|
2
|
+
|
|
3
|
+
import type { IDbSourceClient } from '@e-mc/db/types';
|
|
4
|
+
|
|
5
|
+
import type { MariaDBCredential, MariaDBDataSource } from '../types';
|
|
6
|
+
|
|
7
|
+
declare const MariaDB: IDbSourceClient<MariaDBDataSource> & {
|
|
8
|
+
setAuthentication(this: IDb, credential: MariaDBCredential): void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
11
|
export = MariaDB;
|
package/client/pool.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
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 MariaDBPool extends DbPool {
|
|
6
|
+
static asString(credential) {
|
|
7
|
+
if ((credential.host || credential.socketPath) && 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.getConnection();
|
|
43
|
+
}
|
|
44
|
+
async close() {
|
|
45
|
+
return this.client.end();
|
|
46
|
+
}
|
|
47
|
+
isEmpty() {
|
|
48
|
+
const client = this.client;
|
|
49
|
+
return this.closed || client.activeConnections() === 0 && client.taskQueueSize() === 0;
|
|
50
|
+
}
|
|
51
|
+
get closed() {
|
|
52
|
+
return this.client.closed;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
MariaDBPool.CACHE_UNUSED = ['connectTimeout', 'socketTimeout', 'compress', 'keepAliveDelay', 'acquireTimeout', 'connectionLimit', 'idleTimeout', 'initializationTimeout', 'minDelayValidation', 'minimumIdle', 'resetAfterUse', 'noControlAfterUse', 'leakDetectionTimeout'];
|
|
56
|
+
module.exports = MariaDBPool;
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pi-r/mariadb",
|
|
3
|
-
"version": "0.7.
|
|
4
|
-
"description": "MariaDB 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/mariadb"
|
|
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
|
-
"mariadb": "^3.3.
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-r/mariadb",
|
|
3
|
+
"version": "0.7.4",
|
|
4
|
+
"description": "MariaDB 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/mariadb"
|
|
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
|
+
"mariadb": "^3.3.2"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { DbDataSource } from '@e-mc/types/lib/squared';
|
|
2
|
-
|
|
3
|
-
import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
4
|
-
|
|
5
|
-
import type { SecureContextOptions } from 'tls';
|
|
6
|
-
|
|
7
|
-
import type { PoolConfig, QueryConfig } from 'mariadb';
|
|
8
|
-
|
|
9
|
-
export interface MariaDBDataSource<T = unknown> extends DbDataSource<string | QueryConfig, unknown, unknown, MariaDBCredential, string>, ExecuteAction<T> {
|
|
10
|
-
source: "mariadb";
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface MariaDBCredential extends ServerAuth, Omit<PoolConfig, "ssl"> {
|
|
14
|
-
ssl?: boolean | string | SecureContextOptions & { rejectUnauthorized?: boolean };
|
|
1
|
+
import type { DbDataSource } from '@e-mc/types/lib/squared';
|
|
2
|
+
|
|
3
|
+
import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
4
|
+
|
|
5
|
+
import type { SecureContextOptions } from 'tls';
|
|
6
|
+
|
|
7
|
+
import type { PoolConfig, QueryConfig } from 'mariadb';
|
|
8
|
+
|
|
9
|
+
export interface MariaDBDataSource<T = unknown> extends DbDataSource<string | QueryConfig, unknown, unknown, MariaDBCredential, string>, ExecuteAction<T> {
|
|
10
|
+
source: "mariadb";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface MariaDBCredential extends ServerAuth, Omit<PoolConfig, "ssl"> {
|
|
14
|
+
ssl?: boolean | string | SecureContextOptions & { rejectUnauthorized?: boolean };
|
|
15
15
|
}
|