@e-mc/db 0.0.1
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 +11 -0
- package/README.md +5 -0
- package/index.d.ts +5 -0
- package/index.js +288 -0
- package/mongodb/index.d.ts +19 -0
- package/mongodb/index.js +679 -0
- package/mssql/index.d.ts +7 -0
- package/mssql/index.js +505 -0
- package/mysql/index.d.ts +10 -0
- package/mysql/index.js +332 -0
- package/oracle/index.d.ts +7 -0
- package/oracle/index.js +358 -0
- package/package.json +26 -0
- package/pool.d.ts +5 -0
- package/pool.js +144 -0
- package/postgres/index.d.ts +7 -0
- package/postgres/index.js +272 -0
- package/redis/index.d.ts +7 -0
- package/redis/index.js +550 -0
- package/types.d.ts +14 -0
- package/util.d.ts +17 -0
- package/util.js +106 -0
package/util.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasBasicAuth = exports.getBasicAuth = exports.setUUIDKey = exports.checkEmpty = exports.parseConnectionString = exports.parseServerAuth = exports.SQL_COMMAND = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const util_1 = require("../request/util");
|
|
6
|
+
Object.defineProperty(exports, "getBasicAuth", { enumerable: true, get: function () { return util_1.getBasicAuth; } });
|
|
7
|
+
Object.defineProperty(exports, "hasBasicAuth", { enumerable: true, get: function () { return util_1.hasBasicAuth; } });
|
|
8
|
+
var SQL_COMMAND;
|
|
9
|
+
(function (SQL_COMMAND) {
|
|
10
|
+
SQL_COMMAND[SQL_COMMAND["SELECT"] = 1] = "SELECT";
|
|
11
|
+
SQL_COMMAND[SQL_COMMAND["INSERT"] = 2] = "INSERT";
|
|
12
|
+
SQL_COMMAND[SQL_COMMAND["UPDATE"] = 3] = "UPDATE";
|
|
13
|
+
SQL_COMMAND[SQL_COMMAND["DELETE"] = 4] = "DELETE";
|
|
14
|
+
})(SQL_COMMAND = exports.SQL_COMMAND || (exports.SQL_COMMAND = {}));
|
|
15
|
+
function parseServerAuth(credential, port, all) {
|
|
16
|
+
if (typeof port === 'boolean') {
|
|
17
|
+
all = port;
|
|
18
|
+
port = undefined;
|
|
19
|
+
}
|
|
20
|
+
let protocol, server, hostname, username, password, database;
|
|
21
|
+
if ('protocol' in credential) {
|
|
22
|
+
protocol = credential.protocol;
|
|
23
|
+
delete credential.protocol;
|
|
24
|
+
}
|
|
25
|
+
if ('server' in credential) {
|
|
26
|
+
server = credential.server;
|
|
27
|
+
delete credential.server;
|
|
28
|
+
}
|
|
29
|
+
if ('hostname' in credential) {
|
|
30
|
+
hostname = credential.hostname;
|
|
31
|
+
delete credential.hostname;
|
|
32
|
+
}
|
|
33
|
+
if ('port' in credential) {
|
|
34
|
+
const value = +credential.port;
|
|
35
|
+
if (value > 0) {
|
|
36
|
+
port = value;
|
|
37
|
+
credential.port = port;
|
|
38
|
+
if (all) {
|
|
39
|
+
delete credential.port;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
delete credential.port;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if ('username' in credential) {
|
|
47
|
+
username = credential.username;
|
|
48
|
+
delete credential.username;
|
|
49
|
+
}
|
|
50
|
+
if ('password' in credential) {
|
|
51
|
+
password = credential.password;
|
|
52
|
+
if (all) {
|
|
53
|
+
delete credential.password;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if ('database' in credential) {
|
|
57
|
+
database = credential.database;
|
|
58
|
+
if (all) {
|
|
59
|
+
delete credential.database;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (!server) {
|
|
63
|
+
if (hostname) {
|
|
64
|
+
server = hostname + (port ? ':' + port : '');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else if (!hostname) {
|
|
68
|
+
const match = /^\s*([^:]+)(?::(\d+))?\s*$/.exec(server);
|
|
69
|
+
if (match) {
|
|
70
|
+
hostname = match[1];
|
|
71
|
+
if (match[2]) {
|
|
72
|
+
port = +match[2];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { protocol, server, hostname, port, username, password, database };
|
|
77
|
+
}
|
|
78
|
+
exports.parseServerAuth = parseServerAuth;
|
|
79
|
+
function parseConnectionString(value, scheme = 'http') {
|
|
80
|
+
if (!/^[^:]+:\/\//.test(value)) {
|
|
81
|
+
value = scheme + '://' + value;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const { protocol, username, password, hostname, pathname, port, search } = new URL(value);
|
|
85
|
+
const database = pathname.substring(1);
|
|
86
|
+
return { protocol, username: decodeURIComponent(username), password: decodeURIComponent(password), hostname, port, database: decodeURIComponent(/^([^?/#]+)/.exec(database)?.[1] || database), pathname, search };
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.parseConnectionString = parseConnectionString;
|
|
93
|
+
function checkEmpty(value) {
|
|
94
|
+
return value === undefined || value === null ? false : value === 0 || (value instanceof Set ? value.size === 0 : (Array.isArray(value) || (0, types_1.isObject)(value)) && value.length === 0);
|
|
95
|
+
}
|
|
96
|
+
exports.checkEmpty = checkEmpty;
|
|
97
|
+
function setUUIDKey(item, value) {
|
|
98
|
+
var _a;
|
|
99
|
+
if ((0, types_1.isString)(value)) {
|
|
100
|
+
if (!(0, types_1.isPlainObject)(item.credential)) {
|
|
101
|
+
item.credential = {};
|
|
102
|
+
}
|
|
103
|
+
(_a = item.credential).uuidKey || (_a.uuidKey = value);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.setUUIDKey = setUUIDKey;
|