mm_os 3.1.3 → 3.1.6
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 +75 -10
- package/core/com/plugin/drive.js +1 -1
- package/package.json +6 -6
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_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,31 @@ 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_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
|
+
Drive.prototype.update_db_index = async function(db) {
|
|
305
|
+
let indexes = this.config.indexes;
|
|
306
|
+
// 更新索引
|
|
307
|
+
if (indexes) {
|
|
308
|
+
for (var n = 0; n < indexes.length; n++) {
|
|
309
|
+
var m = indexes[n];
|
|
310
|
+
var sql_start = "";
|
|
311
|
+
if (m.type === "UNIQUE") {
|
|
312
|
+
sql_start = "CREATE UNIQUE INDEX `"
|
|
313
|
+
} else {
|
|
314
|
+
sql_start = "CREATE INDEX `";
|
|
315
|
+
}
|
|
316
|
+
var sql = sql_start + m.name + "` ON `" + table + "` (" + m.fields + ");";
|
|
317
|
+
await db.exec(sql_start + m.name + "` ON `" + table + "` (" + m.fields + ");");
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
261
322
|
/**
|
|
262
323
|
* 通过配置更新数据库
|
|
263
324
|
* @param {Object} db 数据库管理器
|
|
@@ -267,8 +328,8 @@ Drive.prototype.update_db = async function(db) {
|
|
|
267
328
|
var cg = this.config;
|
|
268
329
|
db.table = cg.table + "";
|
|
269
330
|
var fields = await db.fields();
|
|
331
|
+
var table = cg.table;
|
|
270
332
|
var list = cg.fields;
|
|
271
|
-
|
|
272
333
|
if (fields.length === 0) {
|
|
273
334
|
var k = cg.key;
|
|
274
335
|
var len = list.length;
|
|
@@ -285,7 +346,7 @@ Drive.prototype.update_db = async function(db) {
|
|
|
285
346
|
} else {
|
|
286
347
|
var commit = cg.title + ":" + cg.description;
|
|
287
348
|
var sql = "alter table `{0}` comment '{1}';".replace('{0}', cg.table).replace('{1}', commit);
|
|
288
|
-
db.exec(sql);
|
|
349
|
+
await db.exec(sql);
|
|
289
350
|
}
|
|
290
351
|
if (fields.length > 0) {
|
|
291
352
|
// 删除配置中没有的字段
|
|
@@ -397,13 +458,14 @@ Drive.prototype.update_db = async function(db) {
|
|
|
397
458
|
|
|
398
459
|
if (arr.length === 0) {
|
|
399
460
|
// 如果没有则添加
|
|
400
|
-
await db.exec("alter table `{0}` add ".replace('{0}',
|
|
461
|
+
await db.exec("alter table `{0}` add ".replace('{0}', table) + sql);
|
|
401
462
|
} else {
|
|
402
463
|
// 如果有则修改
|
|
403
|
-
await db.exec("alter table `{0}` change `{1}` ".replace('{0}',
|
|
464
|
+
await db.exec("alter table `{0}` change `{1}` ".replace('{0}', table).replace('{1}', o
|
|
404
465
|
.name) + sql);
|
|
405
466
|
}
|
|
406
467
|
}
|
|
468
|
+
await this.update_db_index(db);
|
|
407
469
|
} else {
|
|
408
470
|
return "数据表更新失败!";
|
|
409
471
|
}
|
|
@@ -642,7 +704,8 @@ Drive.prototype.new_sql = async function(client, manage, cover) {
|
|
|
642
704
|
if (this.isSet(n, this.query_keyword)) {
|
|
643
705
|
keyword += " || `" + n + "` like '%{0}%'";
|
|
644
706
|
}
|
|
645
|
-
} else if (p === 'date' || p === 'time' || p === 'datetime' || p === 'datetime' || p ===
|
|
707
|
+
} else if (p === 'date' || p === 'time' || p === 'datetime' || p === 'datetime' || p ===
|
|
708
|
+
'timestamp') {
|
|
646
709
|
query[n + "_min"] = "`" + n + "` >= '{0}'";
|
|
647
710
|
query[n + "_max"] = "`" + n + "` <= '{0}'";
|
|
648
711
|
} else if (p !== 'tinyint') {
|
|
@@ -714,7 +777,8 @@ Drive.prototype.new_sql = async function(client, manage, cover) {
|
|
|
714
777
|
delete m.method;
|
|
715
778
|
m.field_hide = [];
|
|
716
779
|
m.name += 2;
|
|
717
|
-
m.field_obj = m.field_obj.replace(",`time_create`", "").replace(",`time_update`", "")
|
|
780
|
+
m.field_obj = m.field_obj.replace(",`time_create`", "").replace(",`time_update`", "")
|
|
781
|
+
.replace(
|
|
718
782
|
",`create_time`", "")
|
|
719
783
|
.replace(",`update_time`", "");
|
|
720
784
|
delete m.query_default;
|
|
@@ -1058,7 +1122,8 @@ Drive.prototype.new_api = async function(client, manage, cover) {
|
|
|
1058
1122
|
var has = false;
|
|
1059
1123
|
for (var i = 0, item; item = lt[i++];) {
|
|
1060
1124
|
var name = item.name;
|
|
1061
|
-
if (name == $.dict.user_id || name === 'uid' || name === 'user_id' || name ===
|
|
1125
|
+
if (name == $.dict.user_id || name === 'uid' || name === 'user_id' || name ===
|
|
1126
|
+
'userid') {
|
|
1062
1127
|
has = true;
|
|
1063
1128
|
break;
|
|
1064
1129
|
}
|
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.6",
|
|
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,17 +42,17 @@
|
|
|
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",
|
|
49
49
|
"mm_redis": "^1.4.2",
|
|
50
50
|
"mm_ret": "^1.4.1",
|
|
51
|
-
"mm_session": "^1.
|
|
51
|
+
"mm_session": "^1.5.0",
|
|
52
52
|
"mm_statics": "^1.5.1",
|
|
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
|
}
|