mm_api 1.1.2 → 1.1.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/api.js +14 -2
- package/package.json +2 -1
package/lib/api.js
CHANGED
|
@@ -19,6 +19,10 @@ function loadOptional(id) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const Param = loadOptional("mm_param/lib/param.js"); // 是MM自带的参数机制,可以不使用
|
|
22
|
+
// sql驱动:优先使用 mm_dao 的 Dao(dao.json 查询构建器,契约 run(query, body, db)),
|
|
23
|
+
// 回退到 mm_sql 的 Sql(仅支持 run(sql, param, timeout) 原始SQL执行)
|
|
24
|
+
const mm_dao = loadOptional("mm_dao");
|
|
25
|
+
const Dao = mm_dao ? mm_dao.Dao : null;
|
|
22
26
|
const Sql = loadOptional("mm_sql/lib/sql.js"); // 是MM自带的sql机制,可以不使用
|
|
23
27
|
|
|
24
28
|
/** param 实例缓存(模块级,替代原全局 param 模块列表) */
|
|
@@ -297,11 +301,15 @@ Api.prototype.getSql = function (file) {
|
|
|
297
301
|
|
|
298
302
|
/**
|
|
299
303
|
* 加载sql模板配置(方案B:读取 sql.json 作为驱动配置,替代旧脚本动态加载)
|
|
304
|
+
* 优先用 mm_dao 的 Dao 构建驱动:Dao 实现了 run(query, body, db) 的旧契约,
|
|
305
|
+
* 能按 sql.json/dao.json 配置将请求参数拼装成 SQL,并通过第三参传入的
|
|
306
|
+
* 数据管理器(db 或 db.new(table) 表模型)执行。仅当 mm_dao 缺失时才
|
|
307
|
+
* 回退到 mm_sql 的 Sql(只支持 run(sql, param, timeout) 原始SQL)。
|
|
300
308
|
* @param {string} file_path sql模板文件路径
|
|
301
309
|
* @returns {object|null} sql驱动实例,未配置或加载失败返回 null
|
|
302
310
|
*/
|
|
303
311
|
Api.prototype._loadSql = function (file_path) {
|
|
304
|
-
if (!file_path || !Sql) {
|
|
312
|
+
if (!file_path || (!Dao && !Sql)) {
|
|
305
313
|
return null;
|
|
306
314
|
}
|
|
307
315
|
var p = file.fullname(file_path, this.getDir());
|
|
@@ -317,7 +325,11 @@ Api.prototype._loadSql = function (file_path) {
|
|
|
317
325
|
cfg.name = cfg.name || this.config.name;
|
|
318
326
|
cfg.config_file = p;
|
|
319
327
|
cfg.dir = path.dirname(p);
|
|
320
|
-
|
|
328
|
+
if (Dao) {
|
|
329
|
+
this.sql = new Dao(cfg, this);
|
|
330
|
+
} else {
|
|
331
|
+
this.sql = new Sql(cfg, this);
|
|
332
|
+
}
|
|
321
333
|
this.updateSql(this.sql);
|
|
322
334
|
return this.sql;
|
|
323
335
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_api",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "API框架,用于实现web api和mvc模式路由请求,负责配置路由路径、访问权限、校验机制;基于 mm_corejs,内置管理器池,无全局/原型扩展依赖",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"mm_corejs": "^1.1.4",
|
|
26
|
+
"mm_dao": "^1.8.2",
|
|
26
27
|
"mm_helper": "^1.0.0",
|
|
27
28
|
"mm_machine": "^3.5.4",
|
|
28
29
|
"mm_param": "^1.1.0",
|