mm_os 4.3.6 → 4.3.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/com/mqtt/drive.js +12 -4
- package/com/mqtt/index.js +60 -25
- package/com/mqtt/script.tpl.js +2 -2
- package/com/nav/tpl/admin_pc/page_channel.vue +5 -5
- package/com/nav/tpl/admin_pc/page_config.vue +5 -5
- package/com/nav/tpl/admin_pc/page_config_form.vue +1 -1
- package/com/nav/tpl/admin_pc/page_default.vue +5 -5
- package/com/nav/tpl/admin_pc/page_form.vue +1 -1
- package/com/nav/tpl/admin_pc/page_lang.vue +5 -5
- package/com/nav/tpl/admin_pc/page_nav.vue +5 -5
- package/com/nav/tpl/admin_pc/page_table.vue +5 -5
- package/com/nav/tpl/admin_pc/page_type.vue +5 -5
- package/com/nav/tpl/admin_pc/page_view.vue +1 -1
- package/com/nav/tpl/dev_pc/page_channel.vue +5 -5
- package/com/nav/tpl/dev_pc/page_config.vue +5 -5
- package/com/nav/tpl/dev_pc/page_default.vue +5 -5
- package/com/nav/tpl/dev_pc/page_form.vue +1 -1
- package/com/nav/tpl/dev_pc/page_nav.vue +5 -5
- package/com/nav/tpl/dev_pc/page_table.vue +5 -5
- package/com/nav/tpl/dev_pc/page_type.vue +6 -6
- package/com/nav/tpl/home_pc/page_channel.vue +5 -5
- package/com/nav/tpl/home_pc/page_default.vue +5 -5
- package/com/nav/tpl/home_pc/page_form.vue +1 -1
- package/com/nav/tpl/home_pc/page_list.vue +5 -5
- package/com/nav/tpl/home_pc/page_nav.vue +5 -5
- package/com/nav/tpl/home_pc/page_type.vue +5 -5
- package/com/nav/tpl/home_pc/page_view.vue +1 -1
- package/com/nav/tpl/home_phone/page_channel.vue +5 -5
- package/com/nav/tpl/home_phone/page_default.vue +5 -5
- package/com/nav/tpl/home_phone/page_form.vue +1 -1
- package/com/nav/tpl/home_phone/page_list.vue +5 -5
- package/com/nav/tpl/home_phone/page_nav.vue +5 -5
- package/com/nav/tpl/home_phone/page_type.vue +5 -5
- package/com/nav/tpl/home_phone/page_view.vue +1 -1
- package/com/pendant/index.js +39 -39
- package/com/sql/drive.js +49 -4
- package/com/template/index.js +141 -141
- package/common/middleware/web_waf/index.js +49 -39
- package/core/app/index.js +711 -710
- package/core/plugin/index.js +13 -43
- package/core/store/index.js +146 -146
- package/package.json +21 -17
- package/server.js +7 -0
- package/com/mqtt/mm_mqtt.js +0 -446
- package/core/store/sql.js +0 -1488
package/core/store/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const { Drive } = require(
|
|
2
|
-
const { idGen } = require(
|
|
3
|
-
const Sql = require(
|
|
1
|
+
const { Drive } = require('mm_machine');
|
|
2
|
+
const { idGen } = require('../../ulits/id_gen.js');
|
|
3
|
+
const Sql = require('../../com/sql/drive.js');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 数据存储基类
|
|
@@ -13,8 +13,8 @@ class Store extends Drive {
|
|
|
13
13
|
* @returns {boolean} 配置是否有效
|
|
14
14
|
*/
|
|
15
15
|
static validateConfig(config) {
|
|
16
|
-
if (!config || typeof config !==
|
|
17
|
-
throw new TypeError(
|
|
16
|
+
if (!config || typeof config !== 'object') {
|
|
17
|
+
throw new TypeError('配置参数必须是对象');
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
Store._validateReqFields(config);
|
|
@@ -31,7 +31,7 @@ class Store extends Drive {
|
|
|
31
31
|
* @param {object} config 配置参数
|
|
32
32
|
*/
|
|
33
33
|
static _validateReqFields(config) {
|
|
34
|
-
var required_fields = [
|
|
34
|
+
var required_fields = ['name', 'cache_type', 'save_type', 'way', 'table'];
|
|
35
35
|
for (var field of required_fields) {
|
|
36
36
|
if (!config[field]) {
|
|
37
37
|
throw new Error(`配置参数缺少必要字段: ${field}`);
|
|
@@ -44,7 +44,7 @@ class Store extends Drive {
|
|
|
44
44
|
* @param {object} config 配置参数
|
|
45
45
|
*/
|
|
46
46
|
static _validateCacheType(config) {
|
|
47
|
-
var valid_cache_types = [
|
|
47
|
+
var valid_cache_types = ['none', 'memory', 'redis', 'mongodb'];
|
|
48
48
|
if (!valid_cache_types.includes(config.cache_type)) {
|
|
49
49
|
throw new Error(`无效的缓存类型: ${config.cache_type}`);
|
|
50
50
|
}
|
|
@@ -55,7 +55,7 @@ class Store extends Drive {
|
|
|
55
55
|
* @param {object} config 配置参数
|
|
56
56
|
*/
|
|
57
57
|
static _validateSaveType(config) {
|
|
58
|
-
var valid_save_types = [
|
|
58
|
+
var valid_save_types = ['none', 'sqlite', 'mysql', 'json'];
|
|
59
59
|
if (!valid_save_types.includes(config.save_type)) {
|
|
60
60
|
throw new Error(`无效的保存类型: ${config.save_type}`);
|
|
61
61
|
}
|
|
@@ -76,11 +76,11 @@ class Store extends Drive {
|
|
|
76
76
|
* @param {object} config 配置参数
|
|
77
77
|
*/
|
|
78
78
|
static _validateNumFields(config) {
|
|
79
|
-
var numeric_fields = [
|
|
79
|
+
var numeric_fields = ['cache_interval', 'save_interval', 'page_size'];
|
|
80
80
|
for (var num_field of numeric_fields) {
|
|
81
81
|
if (
|
|
82
82
|
config[num_field] &&
|
|
83
|
-
(typeof config[num_field] !==
|
|
83
|
+
(typeof config[num_field] !== 'number' || config[num_field] < 0)
|
|
84
84
|
) {
|
|
85
85
|
throw new Error(`${num_field} 必须是正数`);
|
|
86
86
|
}
|
|
@@ -89,23 +89,23 @@ class Store extends Drive {
|
|
|
89
89
|
|
|
90
90
|
static config = {
|
|
91
91
|
// 名称
|
|
92
|
-
name:
|
|
92
|
+
name: 'default',
|
|
93
93
|
// 标题
|
|
94
|
-
title:
|
|
94
|
+
title: '示例标题',
|
|
95
95
|
// 描述
|
|
96
|
-
description:
|
|
96
|
+
description: '示例描述',
|
|
97
97
|
// 入口文件
|
|
98
|
-
main:
|
|
98
|
+
main: '',
|
|
99
99
|
// 作用域,决定加载到什么区域
|
|
100
|
-
scope:
|
|
100
|
+
scope: 'server',
|
|
101
101
|
// 状态 0:禁用 1:启用
|
|
102
102
|
state: 1,
|
|
103
103
|
// 排序,越小越靠前
|
|
104
104
|
sort: 100,
|
|
105
105
|
// 缓存方式 none、memory、redis、mongodb
|
|
106
|
-
cache_type:
|
|
106
|
+
cache_type: 'none',
|
|
107
107
|
// 保存方式 none、sqlite、mysql、json
|
|
108
|
-
save_type:
|
|
108
|
+
save_type: 'none',
|
|
109
109
|
// 缓存更新间隔(秒)
|
|
110
110
|
cache_interval: 600, // 默认10分钟
|
|
111
111
|
// 定时持久化间隔(秒)
|
|
@@ -113,61 +113,61 @@ class Store extends Drive {
|
|
|
113
113
|
// 读写方式 1.直接读写数据库;2.读缓存,写持久存,写后更新缓存;3.读缓存,写缓存,定时持久存;4.读缓存,写持久存,定时更新缓存
|
|
114
114
|
way: 1,
|
|
115
115
|
// 表名
|
|
116
|
-
table:
|
|
116
|
+
table: 'store',
|
|
117
117
|
// 主键
|
|
118
|
-
key:
|
|
118
|
+
key: 'id',
|
|
119
119
|
// ID
|
|
120
|
-
id:
|
|
120
|
+
id: 'id',
|
|
121
121
|
// 默认分页大小
|
|
122
122
|
page_size: 30,
|
|
123
123
|
// 排序方式,{0}表示支持前端传值来排序,传值方式例如:orderby=user_id
|
|
124
|
-
orderby:
|
|
124
|
+
orderby: '{0}',
|
|
125
125
|
// 默认排序方式,当前端没有传值的情况下,采用默认传值方式
|
|
126
|
-
orderby_default:
|
|
126
|
+
orderby_default: '`user_id` desc',
|
|
127
127
|
// 查询列表时返回的字段,{0}表示支持前端传值
|
|
128
|
-
field:
|
|
128
|
+
field: '{0}',
|
|
129
129
|
// 查询对象时返回的字段
|
|
130
|
-
field_obj:
|
|
130
|
+
field_obj: '{0}',
|
|
131
131
|
// 默认返回字段
|
|
132
|
-
field_default:
|
|
132
|
+
field_default: '`username`, `phone`',
|
|
133
133
|
// 需要过滤的字段,*代表泛匹配 前面*表示以xxx结尾,后面*表示以xxx开头,前后*表示包含xxx的过滤
|
|
134
|
-
field_hide: [
|
|
134
|
+
field_hide: ['*password*', '*token*'],
|
|
135
135
|
// 传值分隔符,如果允许多个值,可以通过这个来分割,如果不允许传多个值则设置为空
|
|
136
|
-
separator:
|
|
136
|
+
separator: '|',
|
|
137
137
|
// 过滤参数
|
|
138
138
|
filter: {
|
|
139
139
|
/**
|
|
140
140
|
* 表名
|
|
141
141
|
*/
|
|
142
|
-
table:
|
|
142
|
+
table: 'table',
|
|
143
143
|
/**
|
|
144
144
|
* 查询的页码
|
|
145
145
|
*/
|
|
146
|
-
page:
|
|
146
|
+
page: 'page',
|
|
147
147
|
/**
|
|
148
148
|
* 查询每页条数
|
|
149
149
|
*/
|
|
150
|
-
size:
|
|
150
|
+
size: 'size',
|
|
151
151
|
/**
|
|
152
152
|
* 操作方式: 传入参数method=add, 支持参数 add增、del删、set改、get查,为空则为get
|
|
153
153
|
*/
|
|
154
|
-
method:
|
|
154
|
+
method: 'method',
|
|
155
155
|
/**
|
|
156
156
|
* 排序
|
|
157
157
|
*/
|
|
158
|
-
orderby:
|
|
158
|
+
orderby: 'orderby',
|
|
159
159
|
/**
|
|
160
160
|
* 查询显示的字段
|
|
161
161
|
*/
|
|
162
|
-
field:
|
|
162
|
+
field: 'field',
|
|
163
163
|
/**
|
|
164
164
|
* 统计结果: 统计符合条件的结果数,只有当page等于1或0时才会统计
|
|
165
165
|
*/
|
|
166
|
-
count_ret:
|
|
166
|
+
count_ret: 'count_ret',
|
|
167
167
|
},
|
|
168
168
|
// 允许调用的方法 add增 del删 set改 get查 get_obj查一条 import导入 export导出, 支持什么方式就传什么值,支持多个用空格分隔
|
|
169
169
|
method:
|
|
170
|
-
|
|
170
|
+
'add del set get get_obj import export del_repeat avg sum count update',
|
|
171
171
|
// sql查询语句
|
|
172
172
|
query: {
|
|
173
173
|
// 当username=xx时,转为`username` like '%xxx%'的SQL语法
|
|
@@ -187,9 +187,9 @@ class Store extends Drive {
|
|
|
187
187
|
// 输出sql语句
|
|
188
188
|
log: false,
|
|
189
189
|
// 文件路径, 当调用函数不存在时,会先从文件中加载
|
|
190
|
-
main:
|
|
190
|
+
main: '',
|
|
191
191
|
// 回调函数名 用于决定调用脚本的哪个函数
|
|
192
|
-
func_name:
|
|
192
|
+
func_name: '',
|
|
193
193
|
// 参数 []
|
|
194
194
|
params: null,
|
|
195
195
|
// 导入导出格式,转换导入、导出Eexcel时字段名和字段值
|
|
@@ -197,9 +197,9 @@ class Store extends Drive {
|
|
|
197
197
|
// 去重条件,需要查重、并去重的字段在这里写
|
|
198
198
|
del_repeat: {
|
|
199
199
|
// 判断重复的字段
|
|
200
|
-
|
|
200
|
+
groupby: '',
|
|
201
201
|
// 排序方式
|
|
202
|
-
|
|
202
|
+
orderby: '',
|
|
203
203
|
},
|
|
204
204
|
};
|
|
205
205
|
|
|
@@ -212,7 +212,7 @@ class Store extends Drive {
|
|
|
212
212
|
// 验证配置参数
|
|
213
213
|
Store.validateConfig({ ...Store.config, ...config });
|
|
214
214
|
|
|
215
|
-
super({ type:
|
|
215
|
+
super({ type: 'store', ...Store.config, ...config }, parent);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
|
|
@@ -275,7 +275,7 @@ Store.prototype._initCore = async function (db, cache, logger) {
|
|
|
275
275
|
*/
|
|
276
276
|
Store.prototype._addToDb = async function (body) {
|
|
277
277
|
let db = this._sql.db();
|
|
278
|
-
return await this._drive.add(db, body);
|
|
278
|
+
return await this._drive.add(db, {}, body);
|
|
279
279
|
};
|
|
280
280
|
|
|
281
281
|
/**
|
|
@@ -292,8 +292,8 @@ Store.prototype._addToCache = async function (body) {
|
|
|
292
292
|
};
|
|
293
293
|
|
|
294
294
|
// 保存到缓存
|
|
295
|
-
let cache_key = this._genCacheKey(
|
|
296
|
-
let cache_obj_key = this._genCacheKey(
|
|
295
|
+
let cache_key = this._genCacheKey('get', {});
|
|
296
|
+
let cache_obj_key = this._genCacheKey('getObj', { [this.config.id]: temp });
|
|
297
297
|
|
|
298
298
|
// 获取当前列表缓存
|
|
299
299
|
let current = (await this.getCache(cache_key)) || [];
|
|
@@ -313,19 +313,19 @@ Store.prototype._addToCache = async function (body) {
|
|
|
313
313
|
*/
|
|
314
314
|
Store.prototype.add = async function (body) {
|
|
315
315
|
// 入参校验
|
|
316
|
-
if (typeof body !==
|
|
317
|
-
throw new TypeError(
|
|
316
|
+
if (typeof body !== 'object' || body === null) {
|
|
317
|
+
throw new TypeError('添加的数据必须是对象');
|
|
318
318
|
}
|
|
319
319
|
if (Object.keys(body).length === 0) {
|
|
320
|
-
throw new TypeError(
|
|
320
|
+
throw new TypeError('添加的数据不能为空');
|
|
321
321
|
}
|
|
322
322
|
|
|
323
323
|
try {
|
|
324
324
|
let way = this.config.way;
|
|
325
325
|
return await this._addByWay(body, way);
|
|
326
326
|
} catch (error) {
|
|
327
|
-
this.log(
|
|
328
|
-
return $.ret.error(error.code || 500,
|
|
327
|
+
this.log('error', '创建数据失败:', error);
|
|
328
|
+
return $.ret.error(error.code || 500, '创建数据失败');
|
|
329
329
|
}
|
|
330
330
|
};
|
|
331
331
|
|
|
@@ -373,19 +373,19 @@ Store.prototype._addListToDb = async function (list) {
|
|
|
373
373
|
* @returns {Promise<object>} - 添加结果
|
|
374
374
|
*/
|
|
375
375
|
Store.prototype._addListToCache = async function (list) {
|
|
376
|
-
let cache_key = this._genCacheKey(
|
|
376
|
+
let cache_key = this._genCacheKey('get', {});
|
|
377
377
|
let current = (await this.getCache(cache_key)) || [];
|
|
378
378
|
|
|
379
379
|
// 为每条数据生成临时ID
|
|
380
380
|
let cached = list.map((item) => {
|
|
381
|
-
let temp = item[this.config.id] || idGen.genId(
|
|
381
|
+
let temp = item[this.config.id] || idGen.genId('temp');
|
|
382
382
|
let data = {
|
|
383
383
|
...item,
|
|
384
384
|
[this.config.id]: temp,
|
|
385
385
|
};
|
|
386
386
|
|
|
387
387
|
// 设置单条数据缓存
|
|
388
|
-
let cache_obj_key = this._genCacheKey(
|
|
388
|
+
let cache_obj_key = this._genCacheKey('getObj', { [this.config.id]: temp });
|
|
389
389
|
this.setCache(cache_obj_key, data);
|
|
390
390
|
|
|
391
391
|
return data;
|
|
@@ -413,10 +413,10 @@ Store.prototype._addListToCache = async function (list) {
|
|
|
413
413
|
Store.prototype.addList = async function (list) {
|
|
414
414
|
// 入参校验
|
|
415
415
|
if (!Array.isArray(list)) {
|
|
416
|
-
throw new TypeError(
|
|
416
|
+
throw new TypeError('批量添加的数据必须是数组');
|
|
417
417
|
}
|
|
418
418
|
if (list.length === 0) {
|
|
419
|
-
throw new TypeError(
|
|
419
|
+
throw new TypeError('批量添加的数据不能为空');
|
|
420
420
|
}
|
|
421
421
|
|
|
422
422
|
try {
|
|
@@ -436,14 +436,14 @@ Store.prototype.addList = async function (list) {
|
|
|
436
436
|
// 方式2:写后更新缓存
|
|
437
437
|
if (way === 2 && this._cache && result.result) {
|
|
438
438
|
// 清除列表缓存,下次读取时会自动更新
|
|
439
|
-
let cache_key = this._genCacheKey(
|
|
439
|
+
let cache_key = this._genCacheKey('get', {});
|
|
440
440
|
await this.delCache(cache_key);
|
|
441
441
|
}
|
|
442
442
|
|
|
443
443
|
return this._formatAddListRet(result, list.length);
|
|
444
444
|
} catch (error) {
|
|
445
|
-
this.log(
|
|
446
|
-
return { error: true, message:
|
|
445
|
+
this.log('error', '批量创建数据失败:', error);
|
|
446
|
+
return { error: true, message: '批量创建数据失败' };
|
|
447
447
|
}
|
|
448
448
|
};
|
|
449
449
|
|
|
@@ -507,12 +507,12 @@ Store.prototype._getFromDb = async function (query) {
|
|
|
507
507
|
*/
|
|
508
508
|
Store.prototype.getObj = async function (query = {}) {
|
|
509
509
|
// 入参校验
|
|
510
|
-
if (typeof query !==
|
|
511
|
-
throw new TypeError(
|
|
510
|
+
if (typeof query !== 'object' || query === null) {
|
|
511
|
+
throw new TypeError('查询条件必须是对象');
|
|
512
512
|
}
|
|
513
513
|
|
|
514
514
|
let way = this.config.way;
|
|
515
|
-
let cache_key = this._genCacheKey(
|
|
515
|
+
let cache_key = this._genCacheKey('getObj', query);
|
|
516
516
|
|
|
517
517
|
// 尝试从缓存读取
|
|
518
518
|
let cached = await this._tryGetFromCache(cache_key, way);
|
|
@@ -536,8 +536,8 @@ Store.prototype.getObj = async function (query = {}) {
|
|
|
536
536
|
*/
|
|
537
537
|
Store.prototype.get = async function (query = {}) {
|
|
538
538
|
// 入参校验
|
|
539
|
-
if (typeof query !==
|
|
540
|
-
throw new TypeError(
|
|
539
|
+
if (typeof query !== 'object' || query === null) {
|
|
540
|
+
throw new TypeError('查询条件必须是对象');
|
|
541
541
|
}
|
|
542
542
|
|
|
543
543
|
return await this._getCache(query);
|
|
@@ -551,7 +551,7 @@ Store.prototype.get = async function (query = {}) {
|
|
|
551
551
|
*/
|
|
552
552
|
Store.prototype._getCache = async function (query) {
|
|
553
553
|
let way = this.config.way;
|
|
554
|
-
let cache_key = this._genCacheKey(
|
|
554
|
+
let cache_key = this._genCacheKey('get', query);
|
|
555
555
|
|
|
556
556
|
// 尝试从缓存读取
|
|
557
557
|
let cached = await this._tryGetListFromCache(cache_key, way);
|
|
@@ -575,10 +575,10 @@ Store.prototype._getCache = async function (query) {
|
|
|
575
575
|
* @param {string} fields - 查询字段
|
|
576
576
|
* @returns {Promise<object|null>} - 查询到的数据对象或null
|
|
577
577
|
*/
|
|
578
|
-
Store.prototype.getById = async function (id, orderby =
|
|
578
|
+
Store.prototype.getById = async function (id, orderby = '', fields = '') {
|
|
579
579
|
// 入参校验
|
|
580
580
|
if (!id && id !== 0) {
|
|
581
|
-
throw new TypeError(
|
|
581
|
+
throw new TypeError('ID不能为空');
|
|
582
582
|
}
|
|
583
583
|
|
|
584
584
|
return await this._getByIdCache(id, orderby, fields);
|
|
@@ -595,7 +595,7 @@ Store.prototype.getById = async function (id, orderby = "", fields = "") {
|
|
|
595
595
|
Store.prototype._getByIdCache = async function (id, orderby, fields) {
|
|
596
596
|
let way = this.config.way;
|
|
597
597
|
let query = this._buildQueryById(id);
|
|
598
|
-
let cache_key = this._genCacheKey(
|
|
598
|
+
let cache_key = this._genCacheKey('getObj', query);
|
|
599
599
|
|
|
600
600
|
// 尝试从缓存读取
|
|
601
601
|
let cached = await this._tryGetFromCache(cache_key, way);
|
|
@@ -629,8 +629,8 @@ Store.prototype.set = async function (query, body) {
|
|
|
629
629
|
this._validateSet(query, body);
|
|
630
630
|
|
|
631
631
|
let way = this.config.way;
|
|
632
|
-
let cache_key = this._genCacheKey(
|
|
633
|
-
let cache_obj_key = this._genCacheKey(
|
|
632
|
+
let cache_key = this._genCacheKey('get', query);
|
|
633
|
+
let cache_obj_key = this._genCacheKey('getObj', query);
|
|
634
634
|
|
|
635
635
|
let result = await this._runSetByWay(
|
|
636
636
|
way,
|
|
@@ -651,14 +651,14 @@ Store.prototype.set = async function (query, body) {
|
|
|
651
651
|
* @throws {TypeError} 参数验证失败时抛出
|
|
652
652
|
*/
|
|
653
653
|
Store.prototype._checkSet = function (query, body) {
|
|
654
|
-
if (typeof query !==
|
|
655
|
-
throw new TypeError(
|
|
654
|
+
if (typeof query !== 'object' || query === null) {
|
|
655
|
+
throw new TypeError('查询条件必须是对象');
|
|
656
656
|
}
|
|
657
|
-
if (typeof body !==
|
|
658
|
-
throw new TypeError(
|
|
657
|
+
if (typeof body !== 'object' || body === null) {
|
|
658
|
+
throw new TypeError('更新内容必须是对象');
|
|
659
659
|
}
|
|
660
660
|
if (Object.keys(body).length === 0) {
|
|
661
|
-
throw new TypeError(
|
|
661
|
+
throw new TypeError('更新内容不能为空');
|
|
662
662
|
}
|
|
663
663
|
};
|
|
664
664
|
|
|
@@ -781,7 +781,7 @@ Store.prototype.setCacheExpire = async function (key, expire_time) {
|
|
|
781
781
|
await this._cache.expire(key, expire_time);
|
|
782
782
|
return true;
|
|
783
783
|
} catch (error) {
|
|
784
|
-
this.log(
|
|
784
|
+
this.log('error', '设置缓存失效时间失败:', error);
|
|
785
785
|
return false;
|
|
786
786
|
}
|
|
787
787
|
};
|
|
@@ -801,7 +801,7 @@ Store.prototype.setCache = async function (action, params, data) {
|
|
|
801
801
|
try {
|
|
802
802
|
return await this._updateCache(action, params, data);
|
|
803
803
|
} catch (error) {
|
|
804
|
-
this.log(
|
|
804
|
+
this.log('error', '更新缓存失败:', error);
|
|
805
805
|
return false;
|
|
806
806
|
}
|
|
807
807
|
};
|
|
@@ -829,13 +829,13 @@ Store.prototype._setCache = async function (action, params, data) {
|
|
|
829
829
|
Store.prototype.setById = async function (id, body) {
|
|
830
830
|
// 入参校验
|
|
831
831
|
if (!id && id !== 0) {
|
|
832
|
-
throw new TypeError(
|
|
832
|
+
throw new TypeError('ID不能为空');
|
|
833
833
|
}
|
|
834
|
-
if (typeof body !==
|
|
835
|
-
throw new TypeError(
|
|
834
|
+
if (typeof body !== 'object' || body === null) {
|
|
835
|
+
throw new TypeError('更新内容必须是对象');
|
|
836
836
|
}
|
|
837
837
|
if (Object.keys(body).length === 0) {
|
|
838
|
-
throw new TypeError(
|
|
838
|
+
throw new TypeError('更新内容不能为空');
|
|
839
839
|
}
|
|
840
840
|
|
|
841
841
|
let way = this.config.way;
|
|
@@ -867,8 +867,8 @@ Store.prototype._buildGetById = function (id) {
|
|
|
867
867
|
*/
|
|
868
868
|
Store.prototype._genCacheKeysForId = function (query) {
|
|
869
869
|
return {
|
|
870
|
-
list_key: this._genCacheKey(
|
|
871
|
-
obj_key: this._genCacheKey(
|
|
870
|
+
list_key: this._genCacheKey('get', query),
|
|
871
|
+
obj_key: this._genCacheKey('getObj', query),
|
|
872
872
|
};
|
|
873
873
|
};
|
|
874
874
|
|
|
@@ -974,16 +974,16 @@ Store.prototype._clearCacheSetById = async function (cache_key, cache_obj_key) {
|
|
|
974
974
|
*/
|
|
975
975
|
Store.prototype.del = async function (query) {
|
|
976
976
|
// 入参校验
|
|
977
|
-
if (typeof query !==
|
|
978
|
-
throw new TypeError(
|
|
977
|
+
if (typeof query !== 'object' || query === null) {
|
|
978
|
+
throw new TypeError('查询条件必须是对象');
|
|
979
979
|
}
|
|
980
980
|
if (Object.keys(query).length === 0) {
|
|
981
|
-
throw new TypeError(
|
|
981
|
+
throw new TypeError('查询条件不能为空');
|
|
982
982
|
}
|
|
983
983
|
|
|
984
984
|
let way = this.config.way;
|
|
985
|
-
let cache_key = this._genCacheKey(
|
|
986
|
-
let cache_obj_key = this._genCacheKey(
|
|
985
|
+
let cache_key = this._genCacheKey('get', query);
|
|
986
|
+
let cache_obj_key = this._genCacheKey('getObj', query);
|
|
987
987
|
|
|
988
988
|
let affected_rows = 0;
|
|
989
989
|
|
|
@@ -1065,7 +1065,7 @@ Store.prototype._clearCacheAfterDel = async function (
|
|
|
1065
1065
|
await this.delCache(cache_obj_key);
|
|
1066
1066
|
|
|
1067
1067
|
// 清除空查询的列表缓存
|
|
1068
|
-
let all_cache_key = this._genCacheKey(
|
|
1068
|
+
let all_cache_key = this._genCacheKey('get', {});
|
|
1069
1069
|
await this.delCache(all_cache_key);
|
|
1070
1070
|
};
|
|
1071
1071
|
|
|
@@ -1077,7 +1077,7 @@ Store.prototype._clearCacheAfterDel = async function (
|
|
|
1077
1077
|
Store.prototype.delById = async function (id) {
|
|
1078
1078
|
// 入参校验
|
|
1079
1079
|
if (!id && id !== 0) {
|
|
1080
|
-
throw new TypeError(
|
|
1080
|
+
throw new TypeError('ID不能为空');
|
|
1081
1081
|
}
|
|
1082
1082
|
|
|
1083
1083
|
try {
|
|
@@ -1085,8 +1085,8 @@ Store.prototype.delById = async function (id) {
|
|
|
1085
1085
|
// 构建查询条件
|
|
1086
1086
|
const query = { [this.config.id]: id };
|
|
1087
1087
|
|
|
1088
|
-
let cache_key = this._genCacheKey(
|
|
1089
|
-
let cache_obj_key = this._genCacheKey(
|
|
1088
|
+
let cache_key = this._genCacheKey('get', query);
|
|
1089
|
+
let cache_obj_key = this._genCacheKey('getObj', query);
|
|
1090
1090
|
|
|
1091
1091
|
let affected_rows = 0;
|
|
1092
1092
|
|
|
@@ -1107,7 +1107,7 @@ Store.prototype.delById = async function (id) {
|
|
|
1107
1107
|
|
|
1108
1108
|
return affected_rows;
|
|
1109
1109
|
} catch (error) {
|
|
1110
|
-
this.log(
|
|
1110
|
+
this.log('error', '根据ID删除数据失败:', error);
|
|
1111
1111
|
return 0;
|
|
1112
1112
|
}
|
|
1113
1113
|
};
|
|
@@ -1136,7 +1136,7 @@ Store.prototype._delByIdDb = async function (query) {
|
|
|
1136
1136
|
*/
|
|
1137
1137
|
Store.prototype._delByIdCache = async function (id, cache_key, cache_obj_key) {
|
|
1138
1138
|
// 从缓存获取当前数据
|
|
1139
|
-
let all_cache_key = this._genCacheKey(
|
|
1139
|
+
let all_cache_key = this._genCacheKey('get', {});
|
|
1140
1140
|
let cached = await this.getCache(all_cache_key);
|
|
1141
1141
|
let affected_rows = 0;
|
|
1142
1142
|
|
|
@@ -1172,7 +1172,7 @@ Store.prototype._clearCacheAfterDel = async function (
|
|
|
1172
1172
|
await this.delCache(cache_obj_key);
|
|
1173
1173
|
|
|
1174
1174
|
// 清除空查询的列表缓存
|
|
1175
|
-
let all_cache_key = this._genCacheKey(
|
|
1175
|
+
let all_cache_key = this._genCacheKey('get', {});
|
|
1176
1176
|
await this.delCache(all_cache_key);
|
|
1177
1177
|
};
|
|
1178
1178
|
|
|
@@ -1183,19 +1183,19 @@ Store.prototype._clearCacheAfterDel = async function (
|
|
|
1183
1183
|
*/
|
|
1184
1184
|
Store.prototype.count = async function (query = {}) {
|
|
1185
1185
|
// 入参校验
|
|
1186
|
-
if (typeof query !==
|
|
1187
|
-
throw new TypeError(
|
|
1186
|
+
if (typeof query !== 'object' || query === null) {
|
|
1187
|
+
throw new TypeError('查询条件必须是对象');
|
|
1188
1188
|
}
|
|
1189
1189
|
|
|
1190
1190
|
try {
|
|
1191
1191
|
let db = this._sql.db();
|
|
1192
1192
|
db.table = this.config.table;
|
|
1193
|
-
db.count_ret =
|
|
1193
|
+
db.count_ret = 'true';
|
|
1194
1194
|
|
|
1195
|
-
let result = await this._drive.getMain(db, query,
|
|
1195
|
+
let result = await this._drive.getMain(db, query, 'count');
|
|
1196
1196
|
return result.result ? result.result.count : 0;
|
|
1197
1197
|
} catch (error) {
|
|
1198
|
-
this.log(
|
|
1198
|
+
this.log('error', '统计数据失败:', error);
|
|
1199
1199
|
return 0;
|
|
1200
1200
|
}
|
|
1201
1201
|
};
|
|
@@ -1208,8 +1208,8 @@ Store.prototype.count = async function (query = {}) {
|
|
|
1208
1208
|
*/
|
|
1209
1209
|
Store.prototype.sum = async function (query, field) {
|
|
1210
1210
|
// 入参校验
|
|
1211
|
-
if (!field || typeof field !==
|
|
1212
|
-
throw new TypeError(
|
|
1211
|
+
if (!field || typeof field !== 'string') {
|
|
1212
|
+
throw new TypeError('字段名必须是字符串');
|
|
1213
1213
|
}
|
|
1214
1214
|
|
|
1215
1215
|
try {
|
|
@@ -1217,7 +1217,7 @@ Store.prototype.sum = async function (query, field) {
|
|
|
1217
1217
|
db.table = this.config.table;
|
|
1218
1218
|
return await db.sum(query, field);
|
|
1219
1219
|
} catch (error) {
|
|
1220
|
-
this.log(
|
|
1220
|
+
this.log('error', '统计字段总和失败:', error);
|
|
1221
1221
|
return 0;
|
|
1222
1222
|
}
|
|
1223
1223
|
};
|
|
@@ -1230,8 +1230,8 @@ Store.prototype.sum = async function (query, field) {
|
|
|
1230
1230
|
*/
|
|
1231
1231
|
Store.prototype.avg = async function (query, field) {
|
|
1232
1232
|
// 入参校验
|
|
1233
|
-
if (!field || typeof field !==
|
|
1234
|
-
throw new TypeError(
|
|
1233
|
+
if (!field || typeof field !== 'string') {
|
|
1234
|
+
throw new TypeError('字段名必须是字符串');
|
|
1235
1235
|
}
|
|
1236
1236
|
|
|
1237
1237
|
try {
|
|
@@ -1239,7 +1239,7 @@ Store.prototype.avg = async function (query, field) {
|
|
|
1239
1239
|
db.table = this.config.table;
|
|
1240
1240
|
return await db.avg(query, field);
|
|
1241
1241
|
} catch (error) {
|
|
1242
|
-
this.log(
|
|
1242
|
+
this.log('error', '统计字段平均值失败:', error);
|
|
1243
1243
|
return 0;
|
|
1244
1244
|
}
|
|
1245
1245
|
};
|
|
@@ -1252,8 +1252,8 @@ Store.prototype.avg = async function (query, field) {
|
|
|
1252
1252
|
*/
|
|
1253
1253
|
Store.prototype.max = async function (query, field) {
|
|
1254
1254
|
// 入参校验
|
|
1255
|
-
if (!field || typeof field !==
|
|
1256
|
-
throw new TypeError(
|
|
1255
|
+
if (!field || typeof field !== 'string') {
|
|
1256
|
+
throw new TypeError('字段名必须是字符串');
|
|
1257
1257
|
}
|
|
1258
1258
|
|
|
1259
1259
|
try {
|
|
@@ -1261,7 +1261,7 @@ Store.prototype.max = async function (query, field) {
|
|
|
1261
1261
|
db.table = this.config.table;
|
|
1262
1262
|
return await db.max(query, field);
|
|
1263
1263
|
} catch (error) {
|
|
1264
|
-
this.log(
|
|
1264
|
+
this.log('error', '统计字段最大值失败:', error);
|
|
1265
1265
|
return 0;
|
|
1266
1266
|
}
|
|
1267
1267
|
};
|
|
@@ -1274,8 +1274,8 @@ Store.prototype.max = async function (query, field) {
|
|
|
1274
1274
|
*/
|
|
1275
1275
|
Store.prototype.min = async function (query, field) {
|
|
1276
1276
|
// 入参校验
|
|
1277
|
-
if (!field || typeof field !==
|
|
1278
|
-
throw new TypeError(
|
|
1277
|
+
if (!field || typeof field !== 'string') {
|
|
1278
|
+
throw new TypeError('字段名必须是字符串');
|
|
1279
1279
|
}
|
|
1280
1280
|
|
|
1281
1281
|
try {
|
|
@@ -1283,7 +1283,7 @@ Store.prototype.min = async function (query, field) {
|
|
|
1283
1283
|
db.table = this.config.table;
|
|
1284
1284
|
return await db.min(query, field);
|
|
1285
1285
|
} catch (error) {
|
|
1286
|
-
this.log(
|
|
1286
|
+
this.log('error', '统计字段最小值失败:', error);
|
|
1287
1287
|
return 0;
|
|
1288
1288
|
}
|
|
1289
1289
|
};
|
|
@@ -1295,10 +1295,10 @@ Store.prototype.min = async function (query, field) {
|
|
|
1295
1295
|
* @param {string} orderby - 排序字段
|
|
1296
1296
|
* @returns {Promise<Array>} - 查询结果数组
|
|
1297
1297
|
*/
|
|
1298
|
-
Store.prototype.distinct = async function (query = {}, field, orderby =
|
|
1298
|
+
Store.prototype.distinct = async function (query = {}, field, orderby = '') {
|
|
1299
1299
|
// 入参校验
|
|
1300
|
-
if (!field || typeof field !==
|
|
1301
|
-
throw new TypeError(
|
|
1300
|
+
if (!field || typeof field !== 'string') {
|
|
1301
|
+
throw new TypeError('去重字段必须是字符串');
|
|
1302
1302
|
}
|
|
1303
1303
|
|
|
1304
1304
|
try {
|
|
@@ -1306,7 +1306,7 @@ Store.prototype.distinct = async function (query = {}, field, orderby = "") {
|
|
|
1306
1306
|
db.table = this.config.table;
|
|
1307
1307
|
return await db.distinct(query, field, orderby);
|
|
1308
1308
|
} catch (error) {
|
|
1309
|
-
this.log(
|
|
1309
|
+
this.log('error', '去重查询数据失败:', error);
|
|
1310
1310
|
return [];
|
|
1311
1311
|
}
|
|
1312
1312
|
};
|
|
@@ -1322,12 +1322,12 @@ Store.prototype.distinct = async function (query = {}, field, orderby = "") {
|
|
|
1322
1322
|
Store.prototype.group = async function (
|
|
1323
1323
|
query,
|
|
1324
1324
|
groupby,
|
|
1325
|
-
fields =
|
|
1326
|
-
orderby =
|
|
1325
|
+
fields = '*',
|
|
1326
|
+
orderby = '',
|
|
1327
1327
|
) {
|
|
1328
1328
|
// 入参校验
|
|
1329
|
-
if (!groupby || typeof groupby !==
|
|
1330
|
-
throw new TypeError(
|
|
1329
|
+
if (!groupby || typeof groupby !== 'string') {
|
|
1330
|
+
throw new TypeError('分组字段必须是字符串');
|
|
1331
1331
|
}
|
|
1332
1332
|
|
|
1333
1333
|
try {
|
|
@@ -1335,7 +1335,7 @@ Store.prototype.group = async function (
|
|
|
1335
1335
|
db.table = this.config.table;
|
|
1336
1336
|
return await db.group(query, groupby, fields, orderby);
|
|
1337
1337
|
} catch (error) {
|
|
1338
|
-
this.log(
|
|
1338
|
+
this.log('error', '分组查询数据失败:', error);
|
|
1339
1339
|
return [];
|
|
1340
1340
|
}
|
|
1341
1341
|
};
|
|
@@ -1349,7 +1349,7 @@ Store.prototype.begin = async function () {
|
|
|
1349
1349
|
let db = this._sql.db();
|
|
1350
1350
|
return await db.begin();
|
|
1351
1351
|
} catch (error) {
|
|
1352
|
-
this.log(
|
|
1352
|
+
this.log('error', '开始事务失败:', error);
|
|
1353
1353
|
return null;
|
|
1354
1354
|
}
|
|
1355
1355
|
};
|
|
@@ -1362,14 +1362,14 @@ Store.prototype.begin = async function () {
|
|
|
1362
1362
|
Store.prototype.commit = async function (txn) {
|
|
1363
1363
|
// 入参校验
|
|
1364
1364
|
if (!txn) {
|
|
1365
|
-
throw new TypeError(
|
|
1365
|
+
throw new TypeError('事务对象不能为空');
|
|
1366
1366
|
}
|
|
1367
1367
|
|
|
1368
1368
|
try {
|
|
1369
1369
|
let db = this._sql.db();
|
|
1370
1370
|
return await db.commit(txn);
|
|
1371
1371
|
} catch (error) {
|
|
1372
|
-
this.log(
|
|
1372
|
+
this.log('error', '提交事务失败:', error);
|
|
1373
1373
|
return false;
|
|
1374
1374
|
}
|
|
1375
1375
|
};
|
|
@@ -1382,14 +1382,14 @@ Store.prototype.commit = async function (txn) {
|
|
|
1382
1382
|
Store.prototype.rollback = async function (txn) {
|
|
1383
1383
|
// 入参校验
|
|
1384
1384
|
if (!txn) {
|
|
1385
|
-
throw new TypeError(
|
|
1385
|
+
throw new TypeError('事务对象不能为空');
|
|
1386
1386
|
}
|
|
1387
1387
|
|
|
1388
1388
|
try {
|
|
1389
1389
|
let db = this._sql.db();
|
|
1390
1390
|
return await db.rollback(txn);
|
|
1391
1391
|
} catch (error) {
|
|
1392
|
-
this.log(
|
|
1392
|
+
this.log('error', '回滚事务失败:', error);
|
|
1393
1393
|
return false;
|
|
1394
1394
|
}
|
|
1395
1395
|
};
|
|
@@ -1402,7 +1402,7 @@ Store.prototype.rollback = async function (txn) {
|
|
|
1402
1402
|
Store.prototype.getCache = async function (key) {
|
|
1403
1403
|
// 入参校验
|
|
1404
1404
|
if (!key) {
|
|
1405
|
-
throw new TypeError(
|
|
1405
|
+
throw new TypeError('缓存键名不能为空');
|
|
1406
1406
|
}
|
|
1407
1407
|
|
|
1408
1408
|
try {
|
|
@@ -1411,7 +1411,7 @@ Store.prototype.getCache = async function (key) {
|
|
|
1411
1411
|
}
|
|
1412
1412
|
return null;
|
|
1413
1413
|
} catch (error) {
|
|
1414
|
-
this.log(
|
|
1414
|
+
this.log('error', '获取缓存失败:', error);
|
|
1415
1415
|
return null;
|
|
1416
1416
|
}
|
|
1417
1417
|
};
|
|
@@ -1426,7 +1426,7 @@ Store.prototype.getCache = async function (key) {
|
|
|
1426
1426
|
Store.prototype.setCache = async function (key, value, expire = 3600) {
|
|
1427
1427
|
// 入参校验
|
|
1428
1428
|
if (!key) {
|
|
1429
|
-
throw new TypeError(
|
|
1429
|
+
throw new TypeError('缓存键名不能为空');
|
|
1430
1430
|
}
|
|
1431
1431
|
|
|
1432
1432
|
try {
|
|
@@ -1435,7 +1435,7 @@ Store.prototype.setCache = async function (key, value, expire = 3600) {
|
|
|
1435
1435
|
}
|
|
1436
1436
|
return false;
|
|
1437
1437
|
} catch (error) {
|
|
1438
|
-
this.log(
|
|
1438
|
+
this.log('error', '设置缓存失败:', error);
|
|
1439
1439
|
return false;
|
|
1440
1440
|
}
|
|
1441
1441
|
};
|
|
@@ -1448,7 +1448,7 @@ Store.prototype.setCache = async function (key, value, expire = 3600) {
|
|
|
1448
1448
|
Store.prototype.delCache = async function (key) {
|
|
1449
1449
|
// 入参校验
|
|
1450
1450
|
if (!key) {
|
|
1451
|
-
throw new TypeError(
|
|
1451
|
+
throw new TypeError('缓存键名不能为空');
|
|
1452
1452
|
}
|
|
1453
1453
|
|
|
1454
1454
|
try {
|
|
@@ -1457,7 +1457,7 @@ Store.prototype.delCache = async function (key) {
|
|
|
1457
1457
|
}
|
|
1458
1458
|
return false;
|
|
1459
1459
|
} catch (error) {
|
|
1460
|
-
this.log(
|
|
1460
|
+
this.log('error', '删除缓存失败:', error);
|
|
1461
1461
|
return false;
|
|
1462
1462
|
}
|
|
1463
1463
|
};
|
|
@@ -1471,7 +1471,7 @@ Store.prototype.delCache = async function (key) {
|
|
|
1471
1471
|
Store.prototype._genCacheKey = function (action, params = {}) {
|
|
1472
1472
|
let base = `${this.config.table}:${action}`;
|
|
1473
1473
|
|
|
1474
|
-
if (!params || typeof params !==
|
|
1474
|
+
if (!params || typeof params !== 'object') {
|
|
1475
1475
|
return base;
|
|
1476
1476
|
}
|
|
1477
1477
|
|
|
@@ -1479,7 +1479,7 @@ Store.prototype._genCacheKey = function (action, params = {}) {
|
|
|
1479
1479
|
let sorted = Object.keys(params)
|
|
1480
1480
|
.sort()
|
|
1481
1481
|
.map((key) => `${key}:${JSON.stringify(params[key])}`)
|
|
1482
|
-
.join(
|
|
1482
|
+
.join('_');
|
|
1483
1483
|
|
|
1484
1484
|
return `${base}:${sorted}`;
|
|
1485
1485
|
};
|
|
@@ -1526,11 +1526,11 @@ Store.prototype._startSaveTimer = function () {
|
|
|
1526
1526
|
// 定时将缓存数据持久化到数据库
|
|
1527
1527
|
this._save_timer = setInterval(() => {
|
|
1528
1528
|
this._saveCacheToDb().catch((error) => {
|
|
1529
|
-
this.log(
|
|
1529
|
+
this.log('error', '定时持久化数据失败:', error);
|
|
1530
1530
|
});
|
|
1531
1531
|
}, this._save_interval * 1000);
|
|
1532
1532
|
|
|
1533
|
-
this.log(
|
|
1533
|
+
this.log('info', `已启动定时持久化定时器,间隔${this._save_interval}秒`);
|
|
1534
1534
|
};
|
|
1535
1535
|
|
|
1536
1536
|
/**
|
|
@@ -1540,11 +1540,11 @@ Store.prototype._startCacheTimer = function () {
|
|
|
1540
1540
|
// 定时从数据库更新缓存
|
|
1541
1541
|
this._cache_timer = setInterval(() => {
|
|
1542
1542
|
this._updateCacheFromDb().catch((error) => {
|
|
1543
|
-
this.log(
|
|
1543
|
+
this.log('error', '定时更新缓存失败:', error);
|
|
1544
1544
|
});
|
|
1545
1545
|
}, this._cache_interval * 1000);
|
|
1546
1546
|
|
|
1547
|
-
this.log(
|
|
1547
|
+
this.log('info', `已启动定时更新缓存定时器,间隔${this._cache_interval}秒`);
|
|
1548
1548
|
};
|
|
1549
1549
|
|
|
1550
1550
|
/**
|
|
@@ -1554,7 +1554,7 @@ Store.prototype._startCacheTimer = function () {
|
|
|
1554
1554
|
Store.prototype._saveCacheToDb = async function () {
|
|
1555
1555
|
try {
|
|
1556
1556
|
// 获取缓存中的所有数据
|
|
1557
|
-
let cache_key = this._genCacheKey(
|
|
1557
|
+
let cache_key = this._genCacheKey('get', {});
|
|
1558
1558
|
let cached = await this.getCache(cache_key);
|
|
1559
1559
|
|
|
1560
1560
|
if (!cached || !Array.isArray(cached)) {
|
|
@@ -1567,9 +1567,9 @@ Store.prototype._saveCacheToDb = async function () {
|
|
|
1567
1567
|
// 批量保存数据到数据库
|
|
1568
1568
|
await this._drive.addList(db, cached);
|
|
1569
1569
|
|
|
1570
|
-
this.log(
|
|
1570
|
+
this.log('info', `成功持久化${cached.length}条数据到数据库`);
|
|
1571
1571
|
} catch (error) {
|
|
1572
|
-
this.log(
|
|
1572
|
+
this.log('error', '持久化缓存到数据库失败:', error);
|
|
1573
1573
|
throw error;
|
|
1574
1574
|
}
|
|
1575
1575
|
};
|
|
@@ -1588,20 +1588,20 @@ Store.prototype._setCacheFromDb = async function () {
|
|
|
1588
1588
|
let data = result.result ? result.result.list : [];
|
|
1589
1589
|
|
|
1590
1590
|
// 更新缓存
|
|
1591
|
-
let cache_key = this._genCacheKey(
|
|
1591
|
+
let cache_key = this._genCacheKey('get', {});
|
|
1592
1592
|
await this.setCache(cache_key, data);
|
|
1593
1593
|
|
|
1594
1594
|
// 更新单条数据缓存
|
|
1595
1595
|
for (let item of data) {
|
|
1596
|
-
let cache_obj_key = this._genCacheKey(
|
|
1596
|
+
let cache_obj_key = this._genCacheKey('getObj', {
|
|
1597
1597
|
[this.config.id]: item[this.config.id],
|
|
1598
1598
|
});
|
|
1599
1599
|
await this.setCache(cache_obj_key, item);
|
|
1600
1600
|
}
|
|
1601
1601
|
|
|
1602
|
-
this.log(
|
|
1602
|
+
this.log('info', `成功从数据库更新${data.length}条数据到缓存`);
|
|
1603
1603
|
} catch (error) {
|
|
1604
|
-
this.log(
|
|
1604
|
+
this.log('error', '从数据库更新缓存失败:', error);
|
|
1605
1605
|
throw error;
|
|
1606
1606
|
}
|
|
1607
1607
|
};
|
|
@@ -1691,7 +1691,7 @@ Store.prototype._updateCacheForWay2 = async function (data) {
|
|
|
1691
1691
|
return;
|
|
1692
1692
|
}
|
|
1693
1693
|
|
|
1694
|
-
let cache_key = this._genCacheKey(
|
|
1694
|
+
let cache_key = this._genCacheKey('get', {});
|
|
1695
1695
|
let cached = (await this.getCache(cache_key)) || [];
|
|
1696
1696
|
|
|
1697
1697
|
// 查找是否已存在
|
|
@@ -1722,7 +1722,7 @@ Store.prototype._updateCacheForWay2List = async function (list) {
|
|
|
1722
1722
|
return;
|
|
1723
1723
|
}
|
|
1724
1724
|
|
|
1725
|
-
let cache_key = this._genCacheKey(
|
|
1725
|
+
let cache_key = this._genCacheKey('get', {});
|
|
1726
1726
|
await this.setCache(cache_key, list);
|
|
1727
1727
|
};
|
|
1728
1728
|
|
|
@@ -1769,7 +1769,7 @@ Store.prototype._addListByWay = async function (list, way) {
|
|
|
1769
1769
|
// 方式2:写后更新缓存
|
|
1770
1770
|
if (way === 2 && this._cache && result && result.result) {
|
|
1771
1771
|
// 清除列表缓存,下次读取时会自动更新
|
|
1772
|
-
let cache_key = this._genCacheKey(
|
|
1772
|
+
let cache_key = this._genCacheKey('get', {});
|
|
1773
1773
|
await this.delCache(cache_key);
|
|
1774
1774
|
}
|
|
1775
1775
|
|
|
@@ -1786,7 +1786,7 @@ Store.prototype._initDrive = async function () {
|
|
|
1786
1786
|
return;
|
|
1787
1787
|
}
|
|
1788
1788
|
|
|
1789
|
-
this._drive = new
|
|
1789
|
+
this._drive = new Sql(this.config);
|
|
1790
1790
|
this._drive.sql = this._sql;
|
|
1791
1791
|
this._drive.cache = this._cache;
|
|
1792
1792
|
};
|