cgserver 10.0.4 → 10.0.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.
Files changed (26) hide show
  1. package/README.md +2 -0
  2. package/dist/lib/Framework/Config/DbConfig.js +3 -3
  3. package/dist/lib/Framework/Database/MSSql/MSSqlManager.js +53 -0
  4. package/dist/lib/Framework/Database/Mongo/MongoBaseService.js +1 -1
  5. package/dist/lib/Framework/Database/Mongo/MongoManager.js +6 -0
  6. package/dist/lib/Framework/Database/Mysql/MysqlBaseService.js +280 -0
  7. package/dist/lib/Framework/Database/Mysql/MysqlManager.js +105 -0
  8. package/dist/lib/Framework/Database/Redis/RedisManager.js +60 -0
  9. package/dist/lib/Framework/Service/MongoAccountService.js +4 -4
  10. package/dist/lib/Framework/Service/MysqlAccountService.js +1 -1
  11. package/dist/lib/Framework/Service/MysqlUserService.js +1 -1
  12. package/dist/lib/Framework/WebServer/Controller/MongoBaseUserController.js +2 -2
  13. package/dist/lib/Framework/WebServer/Controller/MysqlBaseUserController.js +2 -2
  14. package/dist/lib/Framework/cgserver.js +3 -3
  15. package/dist/lib/Framework/global.js +3 -3
  16. package/dist/lib/Framework/index_export_.js +9 -10
  17. package/dist/types/Framework/Config/DbConfig.d.ts +3 -3
  18. package/dist/types/Framework/Database/MSSql/MSSqlManager.d.ts +26 -0
  19. package/dist/types/Framework/Database/Mysql/MysqlBaseService.d.ts +34 -0
  20. package/dist/types/Framework/Database/Mysql/MysqlManager.d.ts +30 -0
  21. package/dist/types/Framework/Database/Redis/RedisManager.d.ts +24 -0
  22. package/dist/types/Framework/Service/MysqlAccountService.d.ts +1 -1
  23. package/dist/types/Framework/Service/MysqlUserService.d.ts +1 -1
  24. package/dist/types/Framework/global.d.ts +3 -3
  25. package/dist/types/Framework/index_export_.d.ts +6 -7
  26. package/package.json +1 -1
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ 10.0.1-10.0.7
2
+ 1、一些列优化和bug修正
1
3
  10.0.0
2
4
  1、老项目切忌不要轻易升级
3
5
  2、老项目切忌不要轻易升级
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DbConfig = void 0;
4
- const MSSqlManager_1 = require("../Database/MSSqlManager");
5
- const MysqlManager_1 = require("../Database/MysqlManager");
6
- const RedisManager_1 = require("../Database/RedisManager");
4
+ const MSSqlManager_1 = require("../Database/MSSql/MSSqlManager");
5
+ const MysqlManager_1 = require("../Database/Mysql/MysqlManager");
6
+ const RedisManager_1 = require("../Database/Redis/RedisManager");
7
7
  class DbConfig {
8
8
  redis = new RedisManager_1.RedisConfig();
9
9
  mongos = [];
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gMSSqlMgr = exports.MSSqlManager = exports.MssqlReturn = exports.MSSqlConfig = void 0;
4
+ const mssql = require("mssql");
5
+ const DBCache_1 = require("../Decorator/DBCache");
6
+ class MSSqlConfig {
7
+ open = false;
8
+ auto = false;
9
+ domain = '127.0.0.1';
10
+ port = 3306;
11
+ user = 'root';
12
+ password = 'root';
13
+ database = 'gameall';
14
+ charset = 'utf8mb4';
15
+ }
16
+ exports.MSSqlConfig = MSSqlConfig;
17
+ class MssqlReturn {
18
+ error = null;
19
+ fields = null;
20
+ list = null;
21
+ }
22
+ exports.MssqlReturn = MssqlReturn;
23
+ class MSSqlManager {
24
+ _init_cbs = [];
25
+ _pool = null;
26
+ get pool() {
27
+ return this._pool;
28
+ }
29
+ get isValid() {
30
+ return !!this._pool;
31
+ }
32
+ constructor() {
33
+ }
34
+ async init(cfg) {
35
+ if (this._pool
36
+ || !cfg
37
+ || !cfg.open) {
38
+ return;
39
+ }
40
+ this._pool = await mssql.connect(cfg);
41
+ console.log("mssql config=" + JSON.stringify(cfg));
42
+ //这个的初始化位置不能变,必须位于cbs前,pool后
43
+ await DBCache_1.gDbCache.init();
44
+ for (let i = 0; i < this._init_cbs.length; ++i) {
45
+ this._init_cbs[i]();
46
+ }
47
+ }
48
+ registerInitCb(cb) {
49
+ this._init_cbs.push(cb);
50
+ }
51
+ }
52
+ exports.MSSqlManager = MSSqlManager;
53
+ exports.gMSSqlMgr = new MSSqlManager();
@@ -42,7 +42,7 @@ class MongoBaseService {
42
42
  * @param id
43
43
  */
44
44
  async getById(id) {
45
- let rs = await this.mongoDb.findOne(this._table, null, { id: id });
45
+ let rs = await this.mongoDb.findOne(this._table, { id: id });
46
46
  return rs.one;
47
47
  }
48
48
  async get(where = null, property = null) {
@@ -189,6 +189,9 @@ class MongoExt {
189
189
  * @param collection
190
190
  */
191
191
  async findOne(collection, where = {}, property = {}) {
192
+ if (!where) {
193
+ where = {};
194
+ }
192
195
  this._convertWhere(where);
193
196
  let rs = { errcode: null, one: null };
194
197
  if (!this._mongoDb) {
@@ -209,6 +212,9 @@ class MongoExt {
209
212
  return rs;
210
213
  }
211
214
  async findMany(collection, where = {}, property = {}, sort, skip = 0, limit = 0) {
215
+ if (!where) {
216
+ where = {};
217
+ }
212
218
  this._convertWhere(where);
213
219
  let rs = { errcode: null, list: null };
214
220
  if (!this._mongoDb) {
@@ -0,0 +1,280 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MysqlBaseService = exports.BaseModel = void 0;
4
+ const Log_1 = require("../../Logic/Log");
5
+ const DBCache_1 = require("../Decorator/DBCache");
6
+ const Property_1 = require("../Decorator/Property");
7
+ const MysqlManager_1 = require("./MysqlManager");
8
+ class BaseModel {
9
+ }
10
+ exports.BaseModel = BaseModel;
11
+ class MysqlBaseService {
12
+ _table = "";
13
+ get table() {
14
+ return this._table;
15
+ }
16
+ get version() {
17
+ let table = this._t_type.prototype[Property_1.TableProperty.key];
18
+ return table.version;
19
+ }
20
+ _inited = false;
21
+ get isInited() {
22
+ return this._inited;
23
+ }
24
+ _t_type = null;
25
+ constructor(type) {
26
+ this._t_type = type;
27
+ if (MysqlManager_1.gMysqlMgr.isValid) {
28
+ this._init();
29
+ }
30
+ else {
31
+ MysqlManager_1.gMysqlMgr.registerInitCb(this._init.bind(this));
32
+ }
33
+ }
34
+ async _init() {
35
+ if (this._inited) {
36
+ return;
37
+ }
38
+ this._inited = true;
39
+ let table = this._t_type.prototype[Property_1.TableProperty.key];
40
+ if (!table || !table.table) {
41
+ throw new Error("数据表的类必须要具有Table装饰器");
42
+ }
43
+ this._table = "`" + table.table + "`";
44
+ if (!MysqlManager_1.gMysqlMgr.cfg.auto) {
45
+ //未开启自动创建数据表
46
+ return;
47
+ }
48
+ let droped = await this._checkDropTable(table.version);
49
+ if (!droped) {
50
+ Log_1.gLog.info("table(" + this._table + ")无需升级...");
51
+ //既然版本号没变,就快速返回
52
+ return;
53
+ }
54
+ let primary_key = null;
55
+ let sql = "create table if not exists " + this._table + " (";
56
+ for (let key in table.items) {
57
+ let item = table.items[key];
58
+ sql += "`" + key + "`" + " " + item.type;
59
+ if (item.type == Property_1.EPropertyType.Varchar
60
+ || item.type == Property_1.EPropertyType.Char
61
+ || item.type == Property_1.EPropertyType.NVarchar) {
62
+ sql += "(" + item.type_len + ")";
63
+ }
64
+ if (item.is_notnull) {
65
+ sql += " not null";
66
+ }
67
+ if (item.default != undefined && !item.is_primary) {
68
+ sql += " default \'" + item.default + "\'";
69
+ }
70
+ if (item.auto_increment) {
71
+ sql += " auto_increment";
72
+ }
73
+ if (item.is_primary) {
74
+ primary_key = key;
75
+ }
76
+ sql += ",";
77
+ }
78
+ if (primary_key) {
79
+ sql += "primary key (`" + primary_key + "`),";
80
+ sql += "unique key `" + primary_key + "_unique` (`" + primary_key + "`)";
81
+ }
82
+ else {
83
+ //去掉最后一个逗号
84
+ sql = sql.substr(0, sql.length - 1);
85
+ }
86
+ sql += ")";
87
+ sql += " engine=" + table.engine;
88
+ if (table.auto_increment != null) {
89
+ sql += " auto_increment=" + table.auto_increment;
90
+ }
91
+ sql += " default charset=" + table.charset;
92
+ if (table.comment) {
93
+ sql += " comment=\'" + table.comment + "\';";
94
+ }
95
+ let sr = await MysqlManager_1.gMysqlMgr.query(sql);
96
+ if (sr.error) {
97
+ Log_1.gLog.error(sr.error);
98
+ throw Error("table(" + this._table + ")创建失败...");
99
+ }
100
+ else {
101
+ DBCache_1.gDbCache.setVersion(this.table, table.version);
102
+ Log_1.gLog.info("table(" + this._table + ")初始化成功...");
103
+ await this._onReCreated();
104
+ }
105
+ }
106
+ async _onReCreated() {
107
+ }
108
+ async _onDroped() {
109
+ }
110
+ async _checkDropTable(cur_version) {
111
+ let local_version = DBCache_1.gDbCache.getVersion(this._table);
112
+ if (local_version == cur_version) {
113
+ return false;
114
+ }
115
+ let sql = "drop table if exists " + this._table;
116
+ let sr = await MysqlManager_1.gMysqlMgr.query(sql);
117
+ if (sr.error) {
118
+ Log_1.gLog.error(sr.error);
119
+ throw Error(sr.error);
120
+ }
121
+ else {
122
+ Log_1.gLog.info("table(" + this._table + ")删除成功...");
123
+ await this._onDroped();
124
+ }
125
+ return true;
126
+ }
127
+ /**
128
+ * 没有id的表不能使用该函数
129
+ * @param id
130
+ */
131
+ async getById(id) {
132
+ let tm = null;
133
+ let sr = await MysqlManager_1.gMysqlMgr.query("select * from " + this._table + " where id=? limit 1", [id]);
134
+ if (sr.error || sr.queryResult.length <= 0) {
135
+ return tm;
136
+ }
137
+ tm = sr.result[0];
138
+ return tm;
139
+ }
140
+ async get(proterty, where, args) {
141
+ let sql = "select ";
142
+ sql += proterty || "*";
143
+ sql += " from " + this._table;
144
+ if (where) {
145
+ sql += " where " + where;
146
+ }
147
+ sql += " limit 1";
148
+ let tm = null;
149
+ let sr = await MysqlManager_1.gMysqlMgr.query(sql, args);
150
+ if (sr.queryResult && sr.queryResult.length > 0) {
151
+ tm = sr.queryResult[0];
152
+ }
153
+ return tm;
154
+ }
155
+ async getTotal(where, args) {
156
+ let sql = "select ";
157
+ sql += "count(*) as num";
158
+ sql += " from " + this._table;
159
+ if (where) {
160
+ sql += " where " + where;
161
+ }
162
+ let total = 0;
163
+ let sr = await MysqlManager_1.gMysqlMgr.query(sql, args);
164
+ if (sr.queryResult && sr.queryResult.length > 0) {
165
+ total = sr.queryResult[0].num || 0;
166
+ }
167
+ return total;
168
+ }
169
+ async gets(proterty, where, args) {
170
+ let sql = "select ";
171
+ sql += proterty || "*";
172
+ sql += " from " + this._table;
173
+ if (where) {
174
+ sql += " where " + where;
175
+ }
176
+ let tms = null;
177
+ let sr = await MysqlManager_1.gMysqlMgr.query(sql, args);
178
+ tms = sr.queryResult;
179
+ return tms;
180
+ }
181
+ async getCount(where, args) {
182
+ let sql = "select count(*) as num from " + this._table;
183
+ if (where) {
184
+ sql += " where " + where;
185
+ }
186
+ let sr = await MysqlManager_1.gMysqlMgr.query(sql, args);
187
+ if (sr.error || sr.queryResult.length <= 0) {
188
+ return 0;
189
+ }
190
+ return sr.result[0]["num"] || 0;
191
+ }
192
+ async getRandoms(num, proterty, where, args) {
193
+ num = num || 5;
194
+ let sql = "select ";
195
+ sql += proterty || "*";
196
+ sql += " from " + this._table;
197
+ if (where) {
198
+ sql += " where " + where;
199
+ }
200
+ sql += " order by rand() limit ?";
201
+ args = args || [];
202
+ args.push(num);
203
+ let tms = null;
204
+ let sr = await MysqlManager_1.gMysqlMgr.query(sql, args);
205
+ tms = sr.queryResult;
206
+ return tms;
207
+ }
208
+ async updateProperty(set, where, args, limit) {
209
+ let sql = "update " + this._table + " set ";
210
+ if (set) {
211
+ sql += set;
212
+ }
213
+ else {
214
+ sql += "?";
215
+ }
216
+ if (where) {
217
+ sql += " where " + where;
218
+ }
219
+ if (limit) {
220
+ sql += " limit " + limit;
221
+ }
222
+ let sr = await MysqlManager_1.gMysqlMgr.query(sql, args);
223
+ return sr;
224
+ }
225
+ async update(model, where, args, limit) {
226
+ let sql = "update " + this._table + " set ?";
227
+ if (!where) {
228
+ where = " id=?";
229
+ }
230
+ sql += " where " + where;
231
+ let id = model["id"];
232
+ delete model["id"];
233
+ let u_m = JSON.parse(JSON.stringify(model));
234
+ if (!args) {
235
+ args = [u_m, id];
236
+ }
237
+ else {
238
+ args.unshift(u_m);
239
+ }
240
+ if (limit) {
241
+ sql += " limit " + limit;
242
+ }
243
+ let sr = await MysqlManager_1.gMysqlMgr.query(sql, args);
244
+ if (id) {
245
+ model["id"] = id;
246
+ }
247
+ return sr;
248
+ }
249
+ async insert(model, ip) {
250
+ let table = model[Property_1.TableProperty.key];
251
+ let id_property = table.items["id"];
252
+ if (id_property) {
253
+ if (id_property.auto_increment) {
254
+ delete model["id"];
255
+ }
256
+ }
257
+ if (table.items["create_time"] && model["create_time"] <= 0) {
258
+ model["create_time"] = Date.now();
259
+ }
260
+ if (table.items["create_ip"] && ip) {
261
+ model["create_ip"] = ip;
262
+ }
263
+ let sql = "insert into " + this._table + " set ?";
264
+ //这步的做法是为了去掉model种的TableProperty.key(___table___)
265
+ model = JSON.parse(JSON.stringify(model));
266
+ let sr = await MysqlManager_1.gMysqlMgr.query(sql, [model]);
267
+ return sr;
268
+ }
269
+ async removeById(id) {
270
+ let sql = "delete from " + this._table + " where id=?";
271
+ let sr = await MysqlManager_1.gMysqlMgr.query(sql, [id]);
272
+ return sr;
273
+ }
274
+ async remove(where, args) {
275
+ let sql = "delete from " + this._table + " where " + where;
276
+ let sr = await MysqlManager_1.gMysqlMgr.query(sql, args);
277
+ return sr;
278
+ }
279
+ }
280
+ exports.MysqlBaseService = MysqlBaseService;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gMysqlMgr = exports.MysqlManager = exports.SqlReturns = exports.SqlReturn = exports.MysqlConfig = void 0;
4
+ const Log_1 = require("../../Logic/Log");
5
+ const _error_1 = require("../../Config/_error_");
6
+ const mysql2 = require("mysql2/promise");
7
+ const DBCache_1 = require("../Decorator/DBCache");
8
+ class MysqlConfig {
9
+ open = false;
10
+ auto = false;
11
+ poolcfg = null;
12
+ }
13
+ exports.MysqlConfig = MysqlConfig;
14
+ class SqlReturn {
15
+ error = null;
16
+ result = null;
17
+ fields = null;
18
+ get queryResult() {
19
+ return this.result;
20
+ }
21
+ get execResult() {
22
+ return this.result;
23
+ }
24
+ }
25
+ exports.SqlReturn = SqlReturn;
26
+ class SqlReturns {
27
+ error = null;
28
+ srs = [];
29
+ }
30
+ exports.SqlReturns = SqlReturns;
31
+ class MysqlManager {
32
+ _init_cbs = [];
33
+ _pool = null;
34
+ get isValid() {
35
+ return !!this._pool;
36
+ }
37
+ _cfg = null;
38
+ get cfg() {
39
+ return this._cfg;
40
+ }
41
+ constructor() {
42
+ }
43
+ async init(cfg) {
44
+ if (this._pool
45
+ || !cfg
46
+ || !cfg.open) {
47
+ return;
48
+ }
49
+ this._cfg = cfg;
50
+ this._pool = mysql2.createPool(cfg.poolcfg);
51
+ console.log("mysql config=" + JSON.stringify(cfg));
52
+ //这个的初始化位置不能变,必须位于cbs前,pool后
53
+ if (cfg.auto) {
54
+ await DBCache_1.gDbCache.init();
55
+ }
56
+ for (let i = 0; i < this._init_cbs.length; ++i) {
57
+ this._init_cbs[i]();
58
+ }
59
+ }
60
+ registerInitCb(cb) {
61
+ this._init_cbs.push(cb);
62
+ }
63
+ async query(sqlStr, values) {
64
+ let sr = new SqlReturn();
65
+ if (!this._pool) {
66
+ //表示没有开通数据库,不用记录错误日志
67
+ sr.error = _error_1.EErrorCode.No_Mysql;
68
+ Log_1.gLog.error(sr.error);
69
+ return sr;
70
+ }
71
+ try {
72
+ const [result, fields] = await this._pool.query(sqlStr, values);
73
+ sr.result = result;
74
+ sr.fields = fields;
75
+ }
76
+ catch (error) {
77
+ sr.error = _error_1.EErrorCode.No_Mysql;
78
+ Log_1.gLog.error(sr.error);
79
+ return sr;
80
+ }
81
+ return sr;
82
+ }
83
+ async transaction(sqls) {
84
+ let srs = new SqlReturns();
85
+ try {
86
+ await this._pool.beginTransaction();
87
+ for (let i = 0; i < sqls.length; ++i) {
88
+ let sql = sqls[i];
89
+ let sr = await this.query(sql.sql, sql.values);
90
+ if (sr.error) {
91
+ srs.error = sr.error;
92
+ await this._pool.rollback();
93
+ return srs;
94
+ }
95
+ }
96
+ await this._pool.commit();
97
+ }
98
+ catch (err) {
99
+ srs.error = err;
100
+ Log_1.gLog.error(err);
101
+ }
102
+ }
103
+ }
104
+ exports.MysqlManager = MysqlManager;
105
+ exports.gMysqlMgr = new MysqlManager();
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gRedisMgr = exports.RedisManager = exports.RedisConfig = void 0;
4
+ const redis = require("redis");
5
+ const Log_1 = require("../../Logic/Log");
6
+ class RedisConfig {
7
+ open = false;
8
+ host = "127.0.0.1";
9
+ port = 6379;
10
+ database = 0;
11
+ password = null;
12
+ }
13
+ exports.RedisConfig = RedisConfig;
14
+ class RedisManager {
15
+ _redis = null;
16
+ get redis() {
17
+ return this._redis;
18
+ }
19
+ _redisCfg = null;
20
+ async init(redisCfg) {
21
+ let p = new Promise((resolve) => {
22
+ if (!redisCfg || !redisCfg.open) {
23
+ resolve(null);
24
+ return;
25
+ }
26
+ if (this._redis) {
27
+ resolve(null);
28
+ return;
29
+ }
30
+ this._redisCfg = redisCfg;
31
+ Log_1.gLog.info("begin connect redis=" + JSON.stringify(redisCfg));
32
+ this._redis = redis.createClient(redisCfg);
33
+ this._redis.on("connect", () => {
34
+ this.onConnect();
35
+ resolve(null);
36
+ });
37
+ this._redis.on("end", this.onEnd.bind(this));
38
+ this._redis.on("error", this.onError.bind(this));
39
+ });
40
+ let ret = await p;
41
+ for (let key in this._redis) {
42
+ if (typeof this._redis[key] == "function") {
43
+ this[key] = this._redis[key].bind(this._redis);
44
+ }
45
+ }
46
+ return ret;
47
+ }
48
+ onConnect() {
49
+ Log_1.gLog.info("redis has connected!");
50
+ }
51
+ onEnd() {
52
+ this._redis = null;
53
+ this.init(this._redisCfg); //重连
54
+ }
55
+ onError(err) {
56
+ Log_1.gLog.info("Error connected=" + this._redis + ": " + err);
57
+ }
58
+ }
59
+ exports.RedisManager = RedisManager;
60
+ exports.gRedisMgr = new RedisManager();
@@ -86,7 +86,7 @@ class MongoAccountService extends MongoBaseService_1.MongoBaseService {
86
86
  * @param openid
87
87
  */
88
88
  async getByThird(unionid, openid) {
89
- let am = await this.get(null, { unionid: unionid, openid: openid });
89
+ let am = await this.get({ unionid: unionid, openid: openid });
90
90
  return am;
91
91
  }
92
92
  /**
@@ -94,11 +94,11 @@ class MongoAccountService extends MongoBaseService_1.MongoBaseService {
94
94
  * @param unionid
95
95
  */
96
96
  async getByUnionid(unionid) {
97
- let am = await this.get(null, { unionid: unionid });
97
+ let am = await this.get({ unionid: unionid });
98
98
  return am;
99
99
  }
100
100
  async getByPhone(phone) {
101
- let am = await this.get(null, { phone: phone + "" });
101
+ let am = await this.get({ phone: phone + "" });
102
102
  return am;
103
103
  }
104
104
  /**
@@ -229,7 +229,7 @@ class MongoAccountService extends MongoBaseService_1.MongoBaseService {
229
229
  }
230
230
  account.login_time = Date.now();
231
231
  account.login_ip = ip;
232
- this.updateOne({ login_time: account.login_time, login_ip: account.login_ip }, { id: account.id });
232
+ this.updateOne({ id: account.id }, { login_time: account.login_time, login_ip: account.login_ip });
233
233
  rs.account = account;
234
234
  return rs;
235
235
  }
@@ -8,7 +8,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.MysqlAccountService = exports.MysqlAccountModel = void 0;
10
10
  const Property_1 = require("../Database/Decorator/Property");
11
- const MysqlBaseService_1 = require("../Database/MysqlBaseService");
11
+ const MysqlBaseService_1 = require("../Database/Mysql/MysqlBaseService");
12
12
  const _error_1 = require("../Config/_error_");
13
13
  const MysqlUserService_1 = require("./MysqlUserService");
14
14
  const Table_1 = require("../Database/Decorator/Table");
@@ -8,7 +8,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.MysqlUserService = exports.GUserSer = exports.MysqlUserModel = void 0;
10
10
  const _ = require("underscore");
11
- const MysqlBaseService_1 = require("../Database/MysqlBaseService");
11
+ const MysqlBaseService_1 = require("../Database/Mysql/MysqlBaseService");
12
12
  const PrimaryKey_1 = require("../Database/Decorator/PrimaryKey");
13
13
  const NotNull_1 = require("../Database/Decorator/NotNull");
14
14
  const Property_1 = require("../Database/Decorator/Property");
@@ -7,7 +7,7 @@ const MongoCacheService_1 = require("../../Service/MongoCacheService");
7
7
  const ini_1 = require("../../Service/ini");
8
8
  const MongoUserService_1 = require("../../Service/MongoUserService");
9
9
  const CacheTool_1 = require("../../Logic/CacheTool");
10
- const RedisManager_1 = require("../../Database/RedisManager");
10
+ const RedisManager_1 = require("../../Database/Redis/RedisManager");
11
11
  class MongoBaseUserController extends BaseController_1.BaseController {
12
12
  _user_session_id = "user_session_id";
13
13
  _self_user = null;
@@ -138,7 +138,7 @@ class MongoBaseUserController extends BaseController_1.BaseController {
138
138
  cm.key = this._session_id;
139
139
  cm.data = user.id;
140
140
  cm.expireAt = Date.now() + time * 1000;
141
- MongoCacheService_1.gMongoCacheSer.updateOne(cm, { key: cm.key }, true);
141
+ MongoCacheService_1.gMongoCacheSer.updateOne({ key: cm.key }, cm, true);
142
142
  }
143
143
  this._self_user = user;
144
144
  }
@@ -7,7 +7,7 @@ const FrameworkConfig_1 = require("../../Config/FrameworkConfig");
7
7
  const MongoCacheService_1 = require("../../Service/MongoCacheService");
8
8
  const ini_1 = require("../../Service/ini");
9
9
  const CacheTool_1 = require("../../Logic/CacheTool");
10
- const RedisManager_1 = require("../../Database/RedisManager");
10
+ const RedisManager_1 = require("../../Database/Redis/RedisManager");
11
11
  class MysqlBaseUserController extends BaseController_1.BaseController {
12
12
  _user_session_id = "user_session_id";
13
13
  _self_user = null;
@@ -138,7 +138,7 @@ class MysqlBaseUserController extends BaseController_1.BaseController {
138
138
  cm.key = this._session_id;
139
139
  cm.data = user.id;
140
140
  cm.expireAt = Date.now() + time * 1000;
141
- MongoCacheService_1.gMongoCacheSer.updateOne(cm, { key: cm.key }, true);
141
+ MongoCacheService_1.gMongoCacheSer.updateOne({ key: cm.key }, cm, true);
142
142
  }
143
143
  this._self_user = user;
144
144
  }
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.gCgServer = exports.CgServer = void 0;
4
4
  const Core_1 = require("./Core/Core");
5
5
  const Config_1 = require("./Config/Config");
6
- const MSSqlManager_1 = require("./Database/MSSqlManager");
7
- const RedisManager_1 = require("./Database/RedisManager");
8
- const MysqlManager_1 = require("./Database/MysqlManager");
6
+ const MSSqlManager_1 = require("./Database/MSSql/MSSqlManager");
7
+ const MysqlManager_1 = require("./Database/Mysql/MysqlManager");
9
8
  const MongoManager_1 = require("./Database/Mongo/MongoManager");
10
9
  const Log_1 = require("./Logic/Log");
11
10
  const EventTool_1 = require("./Logic/EventTool");
11
+ const RedisManager_1 = require("./Database/Redis/RedisManager");
12
12
  class CgServer {
13
13
  _webservers = [];
14
14
  get webServers() {
@@ -4,11 +4,10 @@ exports.global = void 0;
4
4
  const TriggerMgr_1 = require("./AI/TriggerMgr");
5
5
  const ByteTool_1 = require("./Core/ByteTool");
6
6
  const DBCache_1 = require("./Database/Decorator/DBCache");
7
- const MSSqlManager_1 = require("./Database/MSSqlManager");
7
+ const MSSqlManager_1 = require("./Database/MSSql/MSSqlManager");
8
8
  const MongoManager_1 = require("./Database/Mongo/MongoManager");
9
9
  const MongoServiceManager_1 = require("./Database/Mongo/MongoServiceManager");
10
- const MysqlManager_1 = require("./Database/MysqlManager");
11
- const RedisManager_1 = require("./Database/RedisManager");
10
+ const MysqlManager_1 = require("./Database/Mysql/MysqlManager");
12
11
  const CacheTool_1 = require("./Logic/CacheTool");
13
12
  const EventTool_1 = require("./Logic/EventTool");
14
13
  const HttpTool_1 = require("./Logic/HttpTool");
@@ -26,6 +25,7 @@ const WechatTool_1 = require("./ThirdParty/WechatTool");
26
25
  const ControllerManager_1 = require("./WebServer/Engine/ControllerManager");
27
26
  const cgserver_1 = require("./cgserver");
28
27
  const Core_1 = require("./Core/Core");
28
+ const RedisManager_1 = require("./Database/Redis/RedisManager");
29
29
  /**
30
30
  * cg引擎的,全局对象
31
31
  */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ISocketServer = exports.IClientWebSocket = exports.IServerWebSocket = exports.JsonProtoFilter = exports.GoogleProtoFilter = exports.EProtoType = exports.RedisConfig = exports.MysqlConfig = exports.MongoConfig = exports.MSSqlConfig = exports.DbConfig = exports.MongoCacheModel = exports.MongoUserModel = exports.MysqlUserModel = exports.MongoUserService = exports.MysqlUserService = exports.MongoAccountService = exports.MysqlAccountService = exports.EAccountFrom = exports.EUserState = exports.ERoleGroup = exports.RedisManager = exports.SqlReturns = exports.SqlReturn = exports.MysqlBaseService = exports.MongoExt = exports.MongoManager = exports.MongoBaseModel = exports.MysqlBaseModel = exports.MongoBaseService = exports.EPropertyType = exports.Type = exports.Table = exports.Property = exports.PrimaryKey = exports.NotNull = exports.AutoIncrement = exports.Timer = exports.core = exports.IServerConfig = exports.FrameworkConfig = exports.Config = exports.FrameworkErrorCode = exports.Trigger = exports.Point = exports.Entity = exports.BehaviorAI = exports.AStar = exports.AiObject = exports.MongoServiceManager = void 0;
3
+ exports.ISocketServer = exports.IClientWebSocket = exports.IServerWebSocket = exports.JsonProtoFilter = exports.GoogleProtoFilter = exports.EProtoType = exports.RedisManager = exports.RedisConfig = exports.MysqlConfig = exports.MongoConfig = exports.MSSqlConfig = exports.DbConfig = exports.MongoCacheModel = exports.MongoUserModel = exports.MysqlUserModel = exports.MongoUserService = exports.MysqlUserService = exports.MongoAccountService = exports.MysqlAccountService = exports.EAccountFrom = exports.EUserState = exports.ERoleGroup = exports.SqlReturns = exports.SqlReturn = exports.MysqlBaseService = exports.MongoExt = exports.MongoManager = exports.MongoBaseModel = exports.MysqlBaseModel = exports.MongoBaseService = exports.EPropertyType = exports.Type = exports.Table = exports.Property = exports.PrimaryKey = exports.NotNull = exports.AutoIncrement = exports.Timer = exports.core = exports.IServerConfig = exports.FrameworkConfig = exports.Config = exports.FrameworkErrorCode = exports.Trigger = exports.Point = exports.Entity = exports.BehaviorAI = exports.AStar = exports.AiObject = exports.MongoServiceManager = void 0;
4
4
  exports.global = exports.SyncCallServer2 = exports.SyncCallServer = exports.SyncCall2 = exports.SyncCall = exports.IRpcClientWebSocket = exports.IRpcServerWebSocket = exports.RpcConfig = exports.CgMq = exports.Rpc = exports.RpcBaseMsg = exports.EAccountState = exports.WebServerConfig = exports.Response = exports.Request = exports.RazorJs = exports.Engine = exports.JsonCreatorValidate = exports.JsonAuthorityValidate = exports.JsonAdminValidate = exports.CreatorValidate = exports.AuthorityValidate = exports.AdminValidate = exports.MongoAccountModel = exports.MysqlAccountModel = exports.MongoBaseUserController = exports.MysqlBaseUserController = exports.BaseController = exports.IWebServer = exports.AlipayCallBack = exports.AlipayResult = exports.BaseMsg = exports.IWebSocket = void 0;
5
5
  var MongoServiceManager_1 = require("./Database/Mongo/MongoServiceManager");
6
6
  Object.defineProperty(exports, "MongoServiceManager", { enumerable: true, get: function () { return MongoServiceManager_1.MongoServiceManager; } });
@@ -45,19 +45,17 @@ Object.defineProperty(exports, "EPropertyType", { enumerable: true, get: functio
45
45
  ///数据库相关
46
46
  var MongoBaseService_1 = require("./Database/Mongo/MongoBaseService");
47
47
  Object.defineProperty(exports, "MongoBaseService", { enumerable: true, get: function () { return MongoBaseService_1.MongoBaseService; } });
48
- var MysqlBaseService_1 = require("./Database/MysqlBaseService");
48
+ var MysqlBaseService_1 = require("./Database/Mysql/MysqlBaseService");
49
49
  Object.defineProperty(exports, "MysqlBaseModel", { enumerable: true, get: function () { return MysqlBaseService_1.BaseModel; } });
50
50
  var MongoManager_1 = require("./Database/Mongo/MongoManager");
51
51
  Object.defineProperty(exports, "MongoBaseModel", { enumerable: true, get: function () { return MongoManager_1.MongoBaseModel; } });
52
52
  Object.defineProperty(exports, "MongoManager", { enumerable: true, get: function () { return MongoManager_1.MongoManager; } });
53
53
  Object.defineProperty(exports, "MongoExt", { enumerable: true, get: function () { return MongoManager_1.MongoExt; } });
54
- var MysqlBaseService_2 = require("./Database/MysqlBaseService");
54
+ var MysqlBaseService_2 = require("./Database/Mysql/MysqlBaseService");
55
55
  Object.defineProperty(exports, "MysqlBaseService", { enumerable: true, get: function () { return MysqlBaseService_2.MysqlBaseService; } });
56
- var MysqlManager_1 = require("./Database/MysqlManager");
56
+ var MysqlManager_1 = require("./Database/Mysql/MysqlManager");
57
57
  Object.defineProperty(exports, "SqlReturn", { enumerable: true, get: function () { return MysqlManager_1.SqlReturn; } });
58
58
  Object.defineProperty(exports, "SqlReturns", { enumerable: true, get: function () { return MysqlManager_1.SqlReturns; } });
59
- var RedisManager_1 = require("./Database/RedisManager");
60
- Object.defineProperty(exports, "RedisManager", { enumerable: true, get: function () { return RedisManager_1.RedisManager; } });
61
59
  var ini_1 = require("./Service/ini");
62
60
  Object.defineProperty(exports, "ERoleGroup", { enumerable: true, get: function () { return ini_1.ERoleGroup; } });
63
61
  Object.defineProperty(exports, "EUserState", { enumerable: true, get: function () { return ini_1.EUserState; } });
@@ -78,14 +76,15 @@ var MongoCacheService_1 = require("./Service/MongoCacheService");
78
76
  Object.defineProperty(exports, "MongoCacheModel", { enumerable: true, get: function () { return MongoCacheService_1.MongoCacheModel; } });
79
77
  var DbConfig_1 = require("./Config/DbConfig");
80
78
  Object.defineProperty(exports, "DbConfig", { enumerable: true, get: function () { return DbConfig_1.DbConfig; } });
81
- var MSSqlManager_1 = require("./Database/MSSqlManager");
79
+ var MSSqlManager_1 = require("./Database/MSSql/MSSqlManager");
82
80
  Object.defineProperty(exports, "MSSqlConfig", { enumerable: true, get: function () { return MSSqlManager_1.MSSqlConfig; } });
83
81
  var MongoManager_2 = require("./Database/Mongo/MongoManager");
84
82
  Object.defineProperty(exports, "MongoConfig", { enumerable: true, get: function () { return MongoManager_2.MongoConfig; } });
85
- var MysqlManager_2 = require("./Database/MysqlManager");
83
+ var MysqlManager_2 = require("./Database/Mysql/MysqlManager");
86
84
  Object.defineProperty(exports, "MysqlConfig", { enumerable: true, get: function () { return MysqlManager_2.MysqlConfig; } });
87
- var RedisManager_2 = require("./Database/RedisManager");
88
- Object.defineProperty(exports, "RedisConfig", { enumerable: true, get: function () { return RedisManager_2.RedisConfig; } });
85
+ var RedisManager_1 = require("./Database/Redis/RedisManager");
86
+ Object.defineProperty(exports, "RedisConfig", { enumerable: true, get: function () { return RedisManager_1.RedisConfig; } });
87
+ Object.defineProperty(exports, "RedisManager", { enumerable: true, get: function () { return RedisManager_1.RedisManager; } });
89
88
  var IProtoFilter_1 = require("./SocketServer/ProtoFilter/IProtoFilter");
90
89
  Object.defineProperty(exports, "EProtoType", { enumerable: true, get: function () { return IProtoFilter_1.EProtoType; } });
91
90
  var GoogleProtoFilter_1 = require("./SocketServer/ProtoFilter/GoogleProtoFilter");
@@ -1,7 +1,7 @@
1
- import { MSSqlConfig } from "../Database/MSSqlManager";
1
+ import { MSSqlConfig } from "../Database/MSSql/MSSqlManager";
2
2
  import { MongoConfig } from "../Database/Mongo/MongoManager";
3
- import { MysqlConfig } from "../Database/MysqlManager";
4
- import { RedisConfig } from "../Database/RedisManager";
3
+ import { MysqlConfig } from "../Database/Mysql/MysqlManager";
4
+ import { RedisConfig } from "../Database/Redis/RedisManager";
5
5
  export declare class DbConfig {
6
6
  redis: RedisConfig;
7
7
  mongos: MongoConfig[];
@@ -0,0 +1,26 @@
1
+ import * as mssql from "mssql";
2
+ export declare class MSSqlConfig {
3
+ open: boolean;
4
+ auto: boolean;
5
+ domain: string;
6
+ port: number;
7
+ user: string;
8
+ password: string;
9
+ database: string;
10
+ charset: string;
11
+ }
12
+ export declare class MssqlReturn {
13
+ error: any;
14
+ fields: any;
15
+ list: Array<any>;
16
+ }
17
+ export declare class MSSqlManager {
18
+ protected _init_cbs: any[];
19
+ protected _pool: mssql.ConnectionPool;
20
+ get pool(): mssql.ConnectionPool;
21
+ get isValid(): boolean;
22
+ constructor();
23
+ init(cfg: MSSqlConfig): Promise<void>;
24
+ registerInitCb(cb: Function): void;
25
+ }
26
+ export declare let gMSSqlMgr: MSSqlManager;
@@ -0,0 +1,34 @@
1
+ export declare class BaseModel {
2
+ }
3
+ export declare class MysqlBaseService<T extends BaseModel> {
4
+ protected _table: string;
5
+ get table(): string;
6
+ get version(): number;
7
+ protected _inited: boolean;
8
+ get isInited(): boolean;
9
+ protected _t_type: {
10
+ new (): T;
11
+ };
12
+ constructor(type: {
13
+ new (): T;
14
+ });
15
+ protected _init(): Promise<void>;
16
+ protected _onReCreated(): Promise<void>;
17
+ protected _onDroped(): Promise<void>;
18
+ protected _checkDropTable(cur_version: number): Promise<boolean>;
19
+ /**
20
+ * 没有id的表不能使用该函数
21
+ * @param id
22
+ */
23
+ getById(id: any): Promise<T>;
24
+ get(proterty?: string, where?: string, args?: Array<any>): Promise<any>;
25
+ getTotal(where?: string, args?: Array<any>): Promise<number>;
26
+ gets(proterty?: string, where?: string, args?: Array<any>): Promise<any[]>;
27
+ getCount(where?: string, args?: Array<any>): Promise<any>;
28
+ getRandoms(num: number, proterty?: string, where?: string, args?: Array<any>): Promise<any[]>;
29
+ updateProperty(set: string, where?: string, args?: Array<any>, limit?: number): Promise<import("./MysqlManager").SqlReturn>;
30
+ update(model: T, where?: string, args?: Array<any>, limit?: number): Promise<import("./MysqlManager").SqlReturn>;
31
+ insert(model: T, ip?: string): Promise<import("./MysqlManager").SqlReturn>;
32
+ removeById(id: any): Promise<import("./MysqlManager").SqlReturn>;
33
+ remove(where: string, args?: Array<any>): Promise<import("./MysqlManager").SqlReturn>;
34
+ }
@@ -0,0 +1,30 @@
1
+ import * as mysql2 from 'mysql2/promise';
2
+ export declare class MysqlConfig {
3
+ open: boolean;
4
+ auto: boolean;
5
+ poolcfg: mysql2.PoolOptions;
6
+ }
7
+ export declare class SqlReturn {
8
+ error: any;
9
+ result: mysql2.QueryResult;
10
+ fields: any;
11
+ get queryResult(): mysql2.RowDataPacket[];
12
+ get execResult(): mysql2.ResultSetHeader;
13
+ }
14
+ export declare class SqlReturns {
15
+ error: any;
16
+ srs: Array<mysql2.QueryResult>;
17
+ }
18
+ export declare class MysqlManager {
19
+ protected _init_cbs: any[];
20
+ protected _pool: mysql2.Pool;
21
+ get isValid(): boolean;
22
+ protected _cfg: MysqlConfig;
23
+ get cfg(): MysqlConfig;
24
+ constructor();
25
+ init(cfg: MysqlConfig): Promise<void>;
26
+ registerInitCb(cb: Function): void;
27
+ query(sqlStr: string, values?: any): Promise<SqlReturn>;
28
+ transaction(sqls: any[]): Promise<SqlReturns>;
29
+ }
30
+ export declare let gMysqlMgr: MysqlManager;
@@ -0,0 +1,24 @@
1
+ import * as redis from 'redis';
2
+ export declare class RedisConfig {
3
+ open: boolean;
4
+ host: string;
5
+ port: number;
6
+ database: number;
7
+ password: any;
8
+ }
9
+ type RedisClientType = redis.RedisClientType<redis.RedisDefaultModules & redis.RedisModules, redis.RedisFunctions, redis.RedisScripts>;
10
+ export declare class RedisManager {
11
+ protected _redis: RedisClientType;
12
+ get redis(): RedisClientType;
13
+ protected _redisCfg: {
14
+ open: boolean;
15
+ } & redis.RedisClientOptions;
16
+ init(redisCfg: {
17
+ open: boolean;
18
+ } & redis.RedisClientOptions): Promise<unknown>;
19
+ onConnect(): void;
20
+ onEnd(): void;
21
+ onError(err: any): void;
22
+ }
23
+ export declare let gRedisMgr: RedisManager;
24
+ export {};
@@ -1,4 +1,4 @@
1
- import { BaseModel, MysqlBaseService } from '../Database/MysqlBaseService';
1
+ import { BaseModel, MysqlBaseService } from '../Database/Mysql/MysqlBaseService';
2
2
  import { MysqlUserModel } from './MysqlUserService';
3
3
  import { EAccountFrom } from './ini';
4
4
  export declare class MysqlAccountModel extends BaseModel {
@@ -1,4 +1,4 @@
1
- import { MysqlBaseService, BaseModel } from "../Database/MysqlBaseService";
1
+ import { MysqlBaseService, BaseModel } from "../Database/Mysql/MysqlBaseService";
2
2
  import { ERoleGroup } from "./ini";
3
3
  export declare class MysqlUserModel extends BaseModel {
4
4
  id: number;
@@ -8,9 +8,9 @@ export declare class global {
8
8
  static gDbCache: import("./Database/Decorator/DBCache").DBCache;
9
9
  static gTriggerMgr: import("./AI/TriggerMgr").TriggerManager;
10
10
  static gMongoMgr: import("./Database/Mongo/MongoManager").MongoManager;
11
- static gMSSqlMgr: import("./Database/MSSqlManager").MSSqlManager;
12
- static gMysqlMgr: import("./Database/MysqlManager").MysqlManager;
13
- static gRedisMgr: import("./Database/RedisManager").RedisManager;
11
+ static gMSSqlMgr: import("./Database/MSSql/MSSqlManager").MSSqlManager;
12
+ static gMysqlMgr: import("./Database/Mysql/MysqlManager").MysqlManager;
13
+ static gRedisMgr: import("./Database/Redis/RedisManager").RedisManager;
14
14
  static gCacheTool: import("./Logic/CacheTool").CacheTool;
15
15
  static gHttpTool: import("./Logic/HttpTool").HttpTool;
16
16
  static gLog: import("./Logic/Log").Log;
@@ -19,11 +19,10 @@ export { Table } from './Database/Decorator/Table';
19
19
  export { Type } from './Database/Decorator/Type';
20
20
  export { EPropertyType } from './Database/Decorator/Property';
21
21
  export { MongoBaseService } from './Database/Mongo/MongoBaseService';
22
- export { BaseModel as MysqlBaseModel } from './Database/MysqlBaseService';
22
+ export { BaseModel as MysqlBaseModel } from './Database/Mysql/MysqlBaseService';
23
23
  export { MongoBaseModel, MongoManager, MongoExt } from './Database/Mongo/MongoManager';
24
- export { MysqlBaseService } from './Database/MysqlBaseService';
25
- export { SqlReturn, SqlReturns } from './Database/MysqlManager';
26
- export { RedisManager } from './Database/RedisManager';
24
+ export { MysqlBaseService } from './Database/Mysql/MysqlBaseService';
25
+ export { SqlReturn, SqlReturns } from './Database/Mysql/MysqlManager';
27
26
  export { ERoleGroup, EUserState, EAccountFrom } from './Service/ini';
28
27
  export { MysqlAccountService } from './Service/MysqlAccountService';
29
28
  export { MongoAccountService } from './Service/MongoAccountService';
@@ -33,10 +32,10 @@ export { MysqlUserModel } from './Service/MysqlUserService';
33
32
  export { MongoUserModel } from './Service/MongoUserService';
34
33
  export { MongoCacheModel } from './Service/MongoCacheService';
35
34
  export { DbConfig } from './Config/DbConfig';
36
- export { MSSqlConfig } from './Database/MSSqlManager';
35
+ export { MSSqlConfig } from './Database/MSSql/MSSqlManager';
37
36
  export { MongoConfig } from './Database/Mongo/MongoManager';
38
- export { MysqlConfig } from './Database/MysqlManager';
39
- export { RedisConfig } from './Database/RedisManager';
37
+ export { MysqlConfig } from './Database/Mysql/MysqlManager';
38
+ export { RedisConfig, RedisManager } from './Database/Redis/RedisManager';
40
39
  export { EProtoType } from './SocketServer/ProtoFilter/IProtoFilter';
41
40
  export { GoogleProtoFilter } from './SocketServer/ProtoFilter/GoogleProtoFilter';
42
41
  export { IProtoFilter } from './SocketServer/ProtoFilter/IProtoFilter';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cgserver",
3
- "version": "10.0.4",
3
+ "version": "10.0.6",
4
4
  "author": "trojan",
5
5
  "type": "commonjs",
6
6
  "description": "free for all.Websocket or Http",