@less-is-more/less-js 1.2.15 → 1.2.19
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/package.json +10 -10
- package/src/db.js +18 -8
- package/src/redis.js +38 -35
- package/test/test-db.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@less-is-more/less-js",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.19",
|
|
4
4
|
"description": "Fast develop kit for nodejs",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,20 +20,20 @@
|
|
|
20
20
|
"@alicloud/pop-core": "^1.7.10",
|
|
21
21
|
"ejs": "^3.1.6",
|
|
22
22
|
"fs-extra": "^10.0.0",
|
|
23
|
-
"inquirer": "^8.
|
|
23
|
+
"inquirer": "^8.2.0",
|
|
24
24
|
"multiparty": "^4.2.2",
|
|
25
|
-
"mysql2": "^2.
|
|
26
|
-
"pg-hstore": "^2.3.
|
|
25
|
+
"mysql2": "^2.3.3",
|
|
26
|
+
"pg-hstore": "^2.3.4",
|
|
27
27
|
"querystring": "^0.2.1",
|
|
28
|
-
"redis": "^
|
|
29
|
-
"sequelize": "^6.
|
|
30
|
-
"validator": "^13.
|
|
28
|
+
"redis": "^4.0.1",
|
|
29
|
+
"sequelize": "^6.13.0",
|
|
30
|
+
"validator": "^13.7.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"body": "^5.1.0",
|
|
34
|
-
"mocha": "^
|
|
35
|
-
"webpack": "^5.
|
|
36
|
-
"webpack-cli": "^4.
|
|
34
|
+
"mocha": "^9.1.3",
|
|
35
|
+
"webpack": "^5.66.0",
|
|
36
|
+
"webpack-cli": "^4.9.1",
|
|
37
37
|
"webpack-node-externals": "^3.0.0"
|
|
38
38
|
}
|
|
39
39
|
}
|
package/src/db.js
CHANGED
|
@@ -202,16 +202,26 @@ module.exports = class Db {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
static async sql(
|
|
206
|
-
|
|
205
|
+
static async sql(
|
|
206
|
+
sql,
|
|
207
|
+
values = [],
|
|
208
|
+
type = this.SQL_TYPE_SELECT,
|
|
209
|
+
modelFormat = false
|
|
210
|
+
) {
|
|
211
|
+
const result = await this.getInstance().query(sql, {
|
|
207
212
|
type: type,
|
|
208
213
|
replacements: values,
|
|
209
|
-
};
|
|
210
|
-
if (
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
+
});
|
|
215
|
+
if (modelFormat) {
|
|
216
|
+
return JSON.parse(this._toHump(JSON.stringify(result)));
|
|
217
|
+
} else {
|
|
218
|
+
return result;
|
|
214
219
|
}
|
|
215
|
-
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
static _toHump(text) {
|
|
223
|
+
return text.replace(/\_(\w)/g, (all, letter) => {
|
|
224
|
+
return letter.toUpperCase();
|
|
225
|
+
});
|
|
216
226
|
}
|
|
217
227
|
};
|
package/src/redis.js
CHANGED
|
@@ -1,43 +1,46 @@
|
|
|
1
1
|
const redis = require("redis");
|
|
2
|
-
const { promisify } = require("util");
|
|
3
2
|
|
|
4
3
|
module.exports = class Redis {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
static #client;
|
|
5
|
+
static #user;
|
|
6
|
+
static #password;
|
|
7
|
+
static #host;
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
static init(host, user, password) {
|
|
10
|
+
this.#host = host;
|
|
11
|
+
this.#user = user;
|
|
12
|
+
this.#password = password;
|
|
13
|
+
}
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
static async getInstance() {
|
|
16
|
+
if (!this.#client) {
|
|
17
|
+
if (this.#host) {
|
|
18
|
+
let params = {
|
|
19
|
+
socket: { host: this.#host },
|
|
20
|
+
};
|
|
21
|
+
if (this.#user) {
|
|
22
|
+
params.username = this.#user;
|
|
23
|
+
params.password = this.#password;
|
|
24
|
+
}
|
|
25
|
+
this.#client = await redis.createClient(params);
|
|
26
|
+
await this.#client.connect();
|
|
27
|
+
} else {
|
|
28
|
+
throw new Error("Redis not init");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return this.#client;
|
|
32
|
+
}
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
static async exec(name, ...args) {
|
|
35
|
+
let client = await Redis.getInstance();
|
|
36
|
+
return await client[name].bind(client).apply(undefined, args);
|
|
37
|
+
}
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
static formatKey(name, params = {}) {
|
|
40
|
+
let key = name;
|
|
41
|
+
for (let nKey in params) {
|
|
42
|
+
key += ":" + nKey + ":" + params[nKey];
|
|
43
|
+
}
|
|
44
|
+
return key;
|
|
45
|
+
}
|
|
43
46
|
};
|