mm_os 3.1.4 → 3.1.7
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/core/com/api/drive.js +1 -1
- package/core/com/db/drive.js +79 -11
- package/core/com/plugin/drive.js +1 -1
- package/package.json +5 -5
package/core/com/api/drive.js
CHANGED
|
@@ -351,7 +351,7 @@ $.get_state = async function(db, token) {
|
|
|
351
351
|
Drive.prototype.get_state = async function(ctx, db) {
|
|
352
352
|
var o;
|
|
353
353
|
// 获取请求参数
|
|
354
|
-
var u = ctx.session.user;
|
|
354
|
+
var u = ctx.session ? ctx.session.user : null;
|
|
355
355
|
if (u) {
|
|
356
356
|
o = Object.assign({}, u);
|
|
357
357
|
o.token = ctx.session.uuid;
|
package/core/com/db/drive.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const Item = require('mm_machine').Item;
|
|
2
|
-
|
|
3
2
|
const fs = require("fs");
|
|
4
3
|
|
|
5
4
|
if (!$.dict.user_id) {
|
|
@@ -62,9 +61,9 @@ class Drive extends Item {
|
|
|
62
61
|
// 字段
|
|
63
62
|
"fields": [
|
|
64
63
|
/* */
|
|
65
|
-
]
|
|
64
|
+
],
|
|
65
|
+
"indexes": []
|
|
66
66
|
};
|
|
67
|
-
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
|
|
@@ -218,6 +217,49 @@ Drive.prototype.model = function(fields) {
|
|
|
218
217
|
};
|
|
219
218
|
};
|
|
220
219
|
|
|
220
|
+
/**
|
|
221
|
+
* 创建索引字段模型
|
|
222
|
+
* @param {Object} o
|
|
223
|
+
* @return {Object} 返回索引模型
|
|
224
|
+
*/
|
|
225
|
+
Drive.prototype.model_index = function(o) {
|
|
226
|
+
return {
|
|
227
|
+
"name": o.Key_name,
|
|
228
|
+
"type": o.Non_unique ? "unique" : "index",
|
|
229
|
+
"fields": o.Column_name.replace(/`/g, '').split(","),
|
|
230
|
+
"comment": o.Index_comment
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* 从数据库更新索引配置
|
|
236
|
+
* @param {Object} db 数据库管理器
|
|
237
|
+
* @return {Array} 索引列表
|
|
238
|
+
*/
|
|
239
|
+
Drive.prototype.update_file_index = function(db) {
|
|
240
|
+
var sql = "SHOW INDEX FROM `" + this.config.table + "`";
|
|
241
|
+
var rows = db.run(sql);
|
|
242
|
+
var dict = {};
|
|
243
|
+
for (var i = 0; i < rows.length; i++) {
|
|
244
|
+
var o = rows[i];
|
|
245
|
+
if (o.Key_name !== 'PRIMARY') {
|
|
246
|
+
if (!dict[o.Key_name]) {
|
|
247
|
+
dict[o.Key_name] = {
|
|
248
|
+
Column_name: []
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
dict[o.Key_name].Column_name.push(o.Column_name);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
var list = [];
|
|
255
|
+
for (var k in dict) {
|
|
256
|
+
var m = this.model_index(dict[k]);
|
|
257
|
+
list.push(m);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return list;
|
|
261
|
+
}
|
|
262
|
+
|
|
221
263
|
/**
|
|
222
264
|
* 从数据库更新配置
|
|
223
265
|
* @param {Object} db 数据库管理器
|
|
@@ -252,12 +294,35 @@ Drive.prototype.update_file = async function(db, cover) {
|
|
|
252
294
|
list.push(field);
|
|
253
295
|
}
|
|
254
296
|
cg.fields = list;
|
|
297
|
+
cg.index = await this.update_file_index(db);
|
|
255
298
|
if (!cg.name) {
|
|
256
299
|
cg.name = cg.table;
|
|
257
300
|
}
|
|
258
301
|
await this.update_app(cover);
|
|
259
302
|
};
|
|
260
303
|
|
|
304
|
+
/**
|
|
305
|
+
* @param {Object} db
|
|
306
|
+
*/
|
|
307
|
+
Drive.prototype.update_db_index = async function(db) {
|
|
308
|
+
var cg = this.config;
|
|
309
|
+
var indexes = cg.indexes;
|
|
310
|
+
// 更新索引
|
|
311
|
+
if (indexes) {
|
|
312
|
+
var len = indexes.length;
|
|
313
|
+
for (var i = 0; i < len; i++) {
|
|
314
|
+
var o = indexes[i];
|
|
315
|
+
var sql_start = "";
|
|
316
|
+
if (o.type === "unique") {
|
|
317
|
+
sql_start = "CREATE UNIQUE INDEX `"
|
|
318
|
+
} else {
|
|
319
|
+
sql_start = "CREATE INDEX `";
|
|
320
|
+
}
|
|
321
|
+
await db.exec(sql_start + o.name + "` ON `" + table + "` (" + o.fields + ");");
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
261
326
|
/**
|
|
262
327
|
* 通过配置更新数据库
|
|
263
328
|
* @param {Object} db 数据库管理器
|
|
@@ -267,8 +332,8 @@ Drive.prototype.update_db = async function(db) {
|
|
|
267
332
|
var cg = this.config;
|
|
268
333
|
db.table = cg.table + "";
|
|
269
334
|
var fields = await db.fields();
|
|
335
|
+
var table = cg.table;
|
|
270
336
|
var list = cg.fields;
|
|
271
|
-
|
|
272
337
|
if (fields.length === 0) {
|
|
273
338
|
var k = cg.key;
|
|
274
339
|
var len = list.length;
|
|
@@ -285,7 +350,7 @@ Drive.prototype.update_db = async function(db) {
|
|
|
285
350
|
} else {
|
|
286
351
|
var commit = cg.title + ":" + cg.description;
|
|
287
352
|
var sql = "alter table `{0}` comment '{1}';".replace('{0}', cg.table).replace('{1}', commit);
|
|
288
|
-
db.exec(sql);
|
|
353
|
+
await db.exec(sql);
|
|
289
354
|
}
|
|
290
355
|
if (fields.length > 0) {
|
|
291
356
|
// 删除配置中没有的字段
|
|
@@ -397,15 +462,15 @@ Drive.prototype.update_db = async function(db) {
|
|
|
397
462
|
|
|
398
463
|
if (arr.length === 0) {
|
|
399
464
|
// 如果没有则添加
|
|
400
|
-
await db.exec("alter table `{0}` add ".replace('{0}',
|
|
465
|
+
await db.exec("alter table `{0}` add ".replace('{0}', table) + sql);
|
|
401
466
|
} else {
|
|
402
467
|
// 如果有则修改
|
|
403
|
-
await db.exec("alter table `{0}` change `{1}` ".replace('{0}',
|
|
468
|
+
await db.exec("alter table `{0}` change `{1}` ".replace('{0}', table).replace('{1}', o
|
|
404
469
|
.name) + sql);
|
|
405
470
|
}
|
|
406
471
|
}
|
|
407
472
|
} else {
|
|
408
|
-
return "
|
|
473
|
+
return "数据表更新失败";
|
|
409
474
|
}
|
|
410
475
|
};
|
|
411
476
|
|
|
@@ -642,7 +707,8 @@ Drive.prototype.new_sql = async function(client, manage, cover) {
|
|
|
642
707
|
if (this.isSet(n, this.query_keyword)) {
|
|
643
708
|
keyword += " || `" + n + "` like '%{0}%'";
|
|
644
709
|
}
|
|
645
|
-
} else if (p === 'date' || p === 'time' || p === 'datetime' || p === 'datetime' || p ===
|
|
710
|
+
} else if (p === 'date' || p === 'time' || p === 'datetime' || p === 'datetime' || p ===
|
|
711
|
+
'timestamp') {
|
|
646
712
|
query[n + "_min"] = "`" + n + "` >= '{0}'";
|
|
647
713
|
query[n + "_max"] = "`" + n + "` <= '{0}'";
|
|
648
714
|
} else if (p !== 'tinyint') {
|
|
@@ -714,7 +780,8 @@ Drive.prototype.new_sql = async function(client, manage, cover) {
|
|
|
714
780
|
delete m.method;
|
|
715
781
|
m.field_hide = [];
|
|
716
782
|
m.name += 2;
|
|
717
|
-
m.field_obj = m.field_obj.replace(",`time_create`", "").replace(",`time_update`", "")
|
|
783
|
+
m.field_obj = m.field_obj.replace(",`time_create`", "").replace(",`time_update`", "")
|
|
784
|
+
.replace(
|
|
718
785
|
",`create_time`", "")
|
|
719
786
|
.replace(",`update_time`", "");
|
|
720
787
|
delete m.query_default;
|
|
@@ -1058,7 +1125,8 @@ Drive.prototype.new_api = async function(client, manage, cover) {
|
|
|
1058
1125
|
var has = false;
|
|
1059
1126
|
for (var i = 0, item; item = lt[i++];) {
|
|
1060
1127
|
var name = item.name;
|
|
1061
|
-
if (name == $.dict.user_id || name === 'uid' || name === 'user_id' || name ===
|
|
1128
|
+
if (name == $.dict.user_id || name === 'uid' || name === 'user_id' || name ===
|
|
1129
|
+
'userid') {
|
|
1062
1130
|
has = true;
|
|
1063
1131
|
break;
|
|
1064
1132
|
}
|
package/core/com/plugin/drive.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_os",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.7",
|
|
4
4
|
"description": "这是超级美眉服务端框架,用于快速构建应用程序。",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"author": "邱文武",
|
|
31
31
|
"license": "ISC",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"compressing": "^1.10.
|
|
34
|
-
"koa": "^
|
|
33
|
+
"compressing": "^1.10.3",
|
|
34
|
+
"koa": "^3.0.0",
|
|
35
35
|
"koa-body": "^6.0.1",
|
|
36
36
|
"koa-compress": "^5.1.1",
|
|
37
37
|
"koa-send": "^5.0.1",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"mm_html": "^1.1.7",
|
|
43
43
|
"mm_koa_proxy": "^1.0.1",
|
|
44
44
|
"mm_logs": "^1.2.0",
|
|
45
|
-
"mm_machine": "^2.0.
|
|
45
|
+
"mm_machine": "^2.0.1",
|
|
46
46
|
"mm_mongodb": "^1.4.4",
|
|
47
47
|
"mm_mqtt": "^1.0.7",
|
|
48
48
|
"mm_mysql": "^2.0.2",
|
|
@@ -53,6 +53,6 @@
|
|
|
53
53
|
"mm_tpl": "^2.4.3",
|
|
54
54
|
"mm_xml": "^1.1.7",
|
|
55
55
|
"mosca": "^2.8.3",
|
|
56
|
-
"mqtt": "^5.
|
|
56
|
+
"mqtt": "^5.13.1"
|
|
57
57
|
}
|
|
58
58
|
}
|