cgserver 9.2.0 → 9.2.2
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/README.md
CHANGED
|
@@ -5,7 +5,6 @@ const Property_1 = require("./Decorator/Property");
|
|
|
5
5
|
const MysqlManager_1 = require("./MysqlManager");
|
|
6
6
|
const Log_1 = require("../Logic/Log");
|
|
7
7
|
const DBCache_1 = require("./Decorator/DBCache");
|
|
8
|
-
const IServerConfig_1 = require("../Config/IServerConfig");
|
|
9
8
|
class BaseModel {
|
|
10
9
|
}
|
|
11
10
|
exports.BaseModel = BaseModel;
|
|
@@ -42,7 +41,7 @@ class MysqlBaseService {
|
|
|
42
41
|
throw new Error("数据表的类必须要具有Table装饰器");
|
|
43
42
|
}
|
|
44
43
|
this._table = "`" + table.table + "`";
|
|
45
|
-
if (!
|
|
44
|
+
if (!MysqlManager_1.GMysqlMgr.cfg.auto) {
|
|
46
45
|
//未开启自动创建数据表
|
|
47
46
|
return;
|
|
48
47
|
}
|
|
@@ -148,8 +147,8 @@ class MysqlBaseService {
|
|
|
148
147
|
sql += " limit 1";
|
|
149
148
|
let tm = null;
|
|
150
149
|
let sr = await MysqlManager_1.GMysqlMgr.query(sql, args);
|
|
151
|
-
if (sr.
|
|
152
|
-
tm = sr.
|
|
150
|
+
if (sr.queryResult && sr.queryResult.length > 0) {
|
|
151
|
+
tm = sr.queryResult[0];
|
|
153
152
|
}
|
|
154
153
|
return tm;
|
|
155
154
|
}
|
|
@@ -162,8 +161,8 @@ class MysqlBaseService {
|
|
|
162
161
|
}
|
|
163
162
|
let total = 0;
|
|
164
163
|
let sr = await MysqlManager_1.GMysqlMgr.query(sql, args);
|
|
165
|
-
if (sr.
|
|
166
|
-
total = sr.
|
|
164
|
+
if (sr.queryResult && sr.queryResult.length > 0) {
|
|
165
|
+
total = sr.queryResult[0].num || 0;
|
|
167
166
|
}
|
|
168
167
|
return total;
|
|
169
168
|
}
|
|
@@ -176,7 +175,7 @@ class MysqlBaseService {
|
|
|
176
175
|
}
|
|
177
176
|
let tms = null;
|
|
178
177
|
let sr = await MysqlManager_1.GMysqlMgr.query(sql, args);
|
|
179
|
-
tms = sr.
|
|
178
|
+
tms = sr.queryResult;
|
|
180
179
|
return tms;
|
|
181
180
|
}
|
|
182
181
|
async getCount(where, args) {
|
|
@@ -203,7 +202,7 @@ class MysqlBaseService {
|
|
|
203
202
|
args.push(num);
|
|
204
203
|
let tms = null;
|
|
205
204
|
let sr = await MysqlManager_1.GMysqlMgr.query(sql, args);
|
|
206
|
-
tms = sr.
|
|
205
|
+
tms = sr.queryResult;
|
|
207
206
|
return tms;
|
|
208
207
|
}
|
|
209
208
|
async updateProperty(set, where, args, limit) {
|
|
@@ -14,7 +14,6 @@ class SqlReturn {
|
|
|
14
14
|
error = null;
|
|
15
15
|
result = null;
|
|
16
16
|
fields = null;
|
|
17
|
-
list = null;
|
|
18
17
|
get queryResult() {
|
|
19
18
|
return this.result;
|
|
20
19
|
}
|
|
@@ -35,6 +34,10 @@ class MysqlManager {
|
|
|
35
34
|
get isValid() {
|
|
36
35
|
return !!this._pool;
|
|
37
36
|
}
|
|
37
|
+
_cfg = null;
|
|
38
|
+
get cfg() {
|
|
39
|
+
return this._cfg;
|
|
40
|
+
}
|
|
38
41
|
constructor() {
|
|
39
42
|
}
|
|
40
43
|
async init(cfg) {
|
|
@@ -43,6 +46,7 @@ class MysqlManager {
|
|
|
43
46
|
|| !cfg.open) {
|
|
44
47
|
return;
|
|
45
48
|
}
|
|
49
|
+
this._cfg = cfg;
|
|
46
50
|
this._pool = mysql2.createPool(cfg.poolcfg);
|
|
47
51
|
console.log("mysql config=" + JSON.stringify(cfg));
|
|
48
52
|
//这个的初始化位置不能变,必须位于cbs前,pool后
|
|
@@ -67,13 +71,6 @@ class MysqlManager {
|
|
|
67
71
|
try {
|
|
68
72
|
const [result, fields] = await this._pool.query(sqlStr, values);
|
|
69
73
|
sr.result = result;
|
|
70
|
-
let rs = result;
|
|
71
|
-
if (rs && rs.length) {
|
|
72
|
-
sr.list = [];
|
|
73
|
-
for (let i = 0; i < rs.length; ++i) {
|
|
74
|
-
sr.list.push(rs[i]);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
74
|
sr.fields = fields;
|
|
78
75
|
}
|
|
79
76
|
catch (error) {
|
|
@@ -98,12 +98,13 @@ class Engine {
|
|
|
98
98
|
let time_str = (Date.now() - time) + "ms";
|
|
99
99
|
Log_1.GLog.info("[" + time_str + "] " + req.method + " " + req.url);
|
|
100
100
|
}
|
|
101
|
-
}).catch(() => {
|
|
101
|
+
}).catch((err) => {
|
|
102
102
|
res.sendStatus(500);
|
|
103
103
|
let exreq = new Request_1.Request(req, this._cfg);
|
|
104
104
|
let info = exreq.getDebugInfo();
|
|
105
105
|
info["tip"] = "server error";
|
|
106
106
|
Log_1.GLog.error(info);
|
|
107
|
+
Log_1.GLog.error(err);
|
|
107
108
|
});
|
|
108
109
|
});
|
|
109
110
|
}
|
|
@@ -8,7 +8,6 @@ export declare class SqlReturn {
|
|
|
8
8
|
error: any;
|
|
9
9
|
result: mysql2.QueryResult;
|
|
10
10
|
fields: any;
|
|
11
|
-
list: Array<any>;
|
|
12
11
|
get queryResult(): mysql2.RowDataPacket[];
|
|
13
12
|
get execResult(): mysql2.ResultSetHeader;
|
|
14
13
|
}
|
|
@@ -21,10 +20,12 @@ declare class MysqlManager {
|
|
|
21
20
|
protected _init_cbs: any[];
|
|
22
21
|
protected _pool: mysql2.Pool;
|
|
23
22
|
get isValid(): boolean;
|
|
23
|
+
protected _cfg: MysqlConfig;
|
|
24
|
+
get cfg(): MysqlConfig;
|
|
24
25
|
constructor();
|
|
25
26
|
init(cfg: MysqlConfig): Promise<void>;
|
|
26
27
|
registerInitCb(cb: Function): void;
|
|
27
|
-
query(sqlStr:
|
|
28
|
+
query(sqlStr: string, values?: any): Promise<SqlReturn>;
|
|
28
29
|
transaction(sqls: any[]): Promise<SqlReturns>;
|
|
29
30
|
}
|
|
30
31
|
export {};
|