mm_dao 1.8.1 → 1.8.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/lib/dao.js +13 -13
- package/lib/manager.js +0 -6
- package/package.json +65 -64
package/lib/dao.js
CHANGED
|
@@ -2,6 +2,7 @@ const path = require('path');
|
|
|
2
2
|
const Item = require('mm_machine').Mod;
|
|
3
3
|
const { string, array, date, file } = require('mm_helper');
|
|
4
4
|
const { getRet } = require('mm_ret');
|
|
5
|
+
const dbAdmin = require('mm_dbs');
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Sql操作驱动类
|
|
@@ -166,9 +167,6 @@ Dao.prototype._getInject = function (key) {
|
|
|
166
167
|
if (value !== undefined && value !== null && value !== '') {
|
|
167
168
|
return value;
|
|
168
169
|
}
|
|
169
|
-
if (this.parent && this.parent.config) {
|
|
170
|
-
return this.parent.config[key];
|
|
171
|
-
}
|
|
172
170
|
return undefined;
|
|
173
171
|
};
|
|
174
172
|
|
|
@@ -718,14 +716,7 @@ Dao.prototype.getParam = async function (db, field) {
|
|
|
718
716
|
*/
|
|
719
717
|
Dao.prototype._getFieldsFromCache = function (cg) {
|
|
720
718
|
var lt = [];
|
|
721
|
-
|
|
722
|
-
var get_db_pool = this._getInject('get_db_pool');
|
|
723
|
-
var db_pool = typeof get_db_pool === 'function' ? get_db_pool() : null;
|
|
724
|
-
if (!db_pool) {
|
|
725
|
-
this.log('warn', '未配置 get_db_pool,跳过字段缓存读取');
|
|
726
|
-
return lt;
|
|
727
|
-
}
|
|
728
|
-
var pool = db_pool['sys'];
|
|
719
|
+
var pool = dbAdmin('os');
|
|
729
720
|
if (pool) {
|
|
730
721
|
var dt = pool.get(cg.table);
|
|
731
722
|
if (dt && dt.config) {
|
|
@@ -1161,17 +1152,26 @@ Dao.prototype.main = async function (params, db) {
|
|
|
1161
1152
|
var safe_table = typeof table === 'string' && string.validate(table, 'username') ? table : '';
|
|
1162
1153
|
|
|
1163
1154
|
// 设置操作的数据表
|
|
1155
|
+
var table_name;
|
|
1164
1156
|
if (string.has(cg.table, '*{0}*')) {
|
|
1165
1157
|
if (table) {
|
|
1166
1158
|
if (!safe_table) {
|
|
1167
1159
|
return getRet().error(30001, '表名包含无效字符');
|
|
1168
1160
|
}
|
|
1169
|
-
|
|
1161
|
+
table_name = cg.table.replace('{0}', safe_table);
|
|
1170
1162
|
} else {
|
|
1171
1163
|
return getRet().error(30001, '表名不能为空');
|
|
1172
1164
|
}
|
|
1173
1165
|
} else {
|
|
1174
|
-
|
|
1166
|
+
table_name = cg.table + '';
|
|
1167
|
+
}
|
|
1168
|
+
db.table = table_name;
|
|
1169
|
+
|
|
1170
|
+
// 兼容传入数据管理器(无 config,只有 new/getSql 等方法)的场景:
|
|
1171
|
+
// 派生一张绑定表名的表模型,使 getSql/getCountSql/groupCountSql 等
|
|
1172
|
+
// 表级方法与 config.filter 可用;传入的已是表模型时保持不变
|
|
1173
|
+
if (db && db.config === undefined && typeof db.new === 'function') {
|
|
1174
|
+
db = db.new(table_name, cg.key);
|
|
1175
1175
|
}
|
|
1176
1176
|
|
|
1177
1177
|
return await this[method](db, qy, { ...body });
|
package/lib/manager.js
CHANGED
|
@@ -39,11 +39,6 @@ class DaoManager extends Manager {
|
|
|
39
39
|
user_id: "user_id",
|
|
40
40
|
token: "x-auth-token",
|
|
41
41
|
},
|
|
42
|
-
/**
|
|
43
|
-
* 数据库池获取函数(可选注入,返回数据库池注册表;未配置则驱动跳过字段缓存)
|
|
44
|
-
* @type {Function|null}
|
|
45
|
-
*/
|
|
46
|
-
get_db_pool: null,
|
|
47
42
|
/**
|
|
48
43
|
* 用户路径(导出目录优先,替代原全局 config 的 user_path)
|
|
49
44
|
* @type {string}
|
|
@@ -115,7 +110,6 @@ DaoManager.prototype.add = function (config) {
|
|
|
115
110
|
var drive = new this.Drive(
|
|
116
111
|
{
|
|
117
112
|
dict: this.config.dict,
|
|
118
|
-
get_db_pool: this.config.get_db_pool,
|
|
119
113
|
user_path: this.config.user_path,
|
|
120
114
|
static_path: this.config.static_path,
|
|
121
115
|
run_path: this.config.run_path,
|
package/package.json
CHANGED
|
@@ -1,64 +1,65 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "mm_dao",
|
|
3
|
+
"version": "1.8.3",
|
|
4
|
+
"description": "一个通用的SQL帮助类,支持通过切换db_type实现对不同数据库的操作,包括MySQL和SQLite等;另提供 manager.js/drive.js 的SQL模板管理器(融合自 mm_os com/sql,基于 mm_corejs,内置管理器池,无全局/原型扩展依赖)",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "node tests/test.js",
|
|
8
|
+
"test": "node tests/test.js",
|
|
9
|
+
"lint": "eslint . --config eslint.config.js",
|
|
10
|
+
"lint:fix": "eslint . --config eslint.config.js --fix",
|
|
11
|
+
"lint:check": "eslint . --config eslint.config.js --max-warnings 0"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://gitee.com/qiuwenwu91/mm_dao.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"mm_mod",
|
|
19
|
+
"mm_infra",
|
|
20
|
+
"mm_runtime",
|
|
21
|
+
"sql",
|
|
22
|
+
"mysql",
|
|
23
|
+
"sql server",
|
|
24
|
+
"sqlite",
|
|
25
|
+
"database",
|
|
26
|
+
"async",
|
|
27
|
+
"await",
|
|
28
|
+
"promise",
|
|
29
|
+
"add",
|
|
30
|
+
"del",
|
|
31
|
+
"set",
|
|
32
|
+
"get",
|
|
33
|
+
"query",
|
|
34
|
+
"run",
|
|
35
|
+
"exec",
|
|
36
|
+
"orm",
|
|
37
|
+
"多数据库",
|
|
38
|
+
"database-adapter"
|
|
39
|
+
],
|
|
40
|
+
"layer": "infra",
|
|
41
|
+
"group": "repo",
|
|
42
|
+
"author": "邱文武",
|
|
43
|
+
"license": "ISC",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://gitee.com/qiuwenwu91/mm_dao/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://gitee.com/qiuwenwu91/mm_dao#readme",
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=12.0.0"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"mm_corejs": "^1.1.4",
|
|
53
|
+
"mm_dbs": "^1.0.1",
|
|
54
|
+
"mm_excel": "^1.2.4",
|
|
55
|
+
"mm_helper": "^1.0.0",
|
|
56
|
+
"mm_machine": "^3.5.4",
|
|
57
|
+
"mm_ret": "^1.4.8",
|
|
58
|
+
"mm_sql": "^1.8.0"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"eslint": "^10.9.1",
|
|
62
|
+
"eslint-plugin-jsdoc": "^64.2.1",
|
|
63
|
+
"mm_eslint": "^1.7.7"
|
|
64
|
+
}
|
|
65
|
+
}
|