@rdyl/node-mysql 0.1.6 → 0.1.8

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/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ## 0.1.5 (2025-08-26)
1
+ ## 0.1.8 (2025-08-26)
2
2
 
3
3
 
4
4
 
package/dist/helper.js CHANGED
@@ -75,8 +75,8 @@ exports.MysqlUpdater = exports.MysqlDeleter = exports.MysqlInserter = exports.My
75
75
  var interface_1 = require("./interface");
76
76
  var utils_1 = require("./utils");
77
77
  var BaseHelper = /** @class */ (function () {
78
- function BaseHelper(db, _tableName) {
79
- this._tableName = _tableName;
78
+ function BaseHelper(table) {
79
+ this.table = table;
80
80
  this.selects = [];
81
81
  this.options = {
82
82
  limit: 0,
@@ -84,7 +84,7 @@ var BaseHelper = /** @class */ (function () {
84
84
  sort: {},
85
85
  };
86
86
  // @ts-ignore
87
- this.pool = global.$MysqlDb[db];
87
+ this.pool = global.$MysqlPool;
88
88
  }
89
89
  Object.defineProperty(BaseHelper.prototype, "selectStat", {
90
90
  get: function () {
@@ -161,13 +161,13 @@ var BaseHelper = /** @class */ (function () {
161
161
  /** @description 查询数据 */
162
162
  var MysqlSelector = /** @class */ (function (_super) {
163
163
  __extends(MysqlSelector, _super);
164
- function MysqlSelector(d, t) {
165
- return _super.call(this, d, t) || this;
164
+ function MysqlSelector(d) {
165
+ return _super.call(this, d) || this;
166
166
  }
167
167
  Object.defineProperty(MysqlSelector.prototype, "sql", {
168
168
  get: function () {
169
169
  var _a = this, selectStat = _a.selectStat, optionStat = _a.optionStat;
170
- var target = "SELECT * FROM ".concat(this._tableName);
170
+ var target = "SELECT * FROM ".concat(this.table);
171
171
  if (selectStat.sql) {
172
172
  target += selectStat.sql;
173
173
  }
@@ -182,7 +182,7 @@ var MysqlSelector = /** @class */ (function (_super) {
182
182
  Object.defineProperty(MysqlSelector.prototype, "countSql", {
183
183
  get: function () {
184
184
  var selectStat = this.selectStat;
185
- var target = "SELECT COUNT(*) AS count FROM users ".concat(this._tableName);
185
+ var target = "SELECT COUNT(*) AS count FROM users ".concat(this.table);
186
186
  if (selectStat.sql) {
187
187
  target += selectStat.sql;
188
188
  }
@@ -301,16 +301,16 @@ exports.MysqlSelector = MysqlSelector;
301
301
  /** @description 插入数据 */
302
302
  var MysqlInserter = /** @class */ (function (_super) {
303
303
  __extends(MysqlInserter, _super);
304
- function MysqlInserter(d, t, fields) {
305
- if (fields === void 0) { fields = []; }
306
- var _this = _super.call(this, d, t) || this;
304
+ function MysqlInserter(t) {
305
+ var _this = _super.call(this, t) || this;
307
306
  _this.values = [];
308
- _this.fields = fields.filter(function (e) { return e !== "id"; });
307
+ // @ts-ignore
308
+ _this.fields = (_this.$MysqlTable[t].fields || []).filter(function (e) { return e !== "id"; });
309
309
  return _this;
310
310
  }
311
311
  Object.defineProperty(MysqlInserter.prototype, "sql", {
312
312
  get: function () {
313
- return "INSERT INTO ".concat(this._tableName, " (").concat(this.fields
313
+ return "INSERT INTO ".concat(this.table, " (").concat(this.fields
314
314
  .map(utils_1.Parser.toDbName)
315
315
  .join(", "), ") \nVALUES (").concat(this.fields.map(function () { return "?"; }).join(", "), ")");
316
316
  },
@@ -372,13 +372,13 @@ exports.MysqlInserter = MysqlInserter;
372
372
  /** @description 删除数据 */
373
373
  var MysqlDeleter = /** @class */ (function (_super) {
374
374
  __extends(MysqlDeleter, _super);
375
- function MysqlDeleter(d, t) {
376
- return _super.call(this, d, t) || this;
375
+ function MysqlDeleter(t) {
376
+ return _super.call(this, t) || this;
377
377
  }
378
378
  Object.defineProperty(MysqlDeleter.prototype, "sql", {
379
379
  get: function () {
380
380
  var _a = this, selectStat = _a.selectStat, optionStat = _a.optionStat;
381
- var target = "DELETE FROM ".concat(this._tableName);
381
+ var target = "DELETE FROM ".concat(this.table);
382
382
  if (selectStat.sql) {
383
383
  target += selectStat.sql;
384
384
  }
@@ -439,8 +439,8 @@ exports.MysqlDeleter = MysqlDeleter;
439
439
  /** @description 更新数据 */
440
440
  var MysqlUpdater = /** @class */ (function (_super) {
441
441
  __extends(MysqlUpdater, _super);
442
- function MysqlUpdater(d, t) {
443
- var _this = _super.call(this, d, t) || this;
442
+ function MysqlUpdater(t) {
443
+ var _this = _super.call(this, t) || this;
444
444
  _this.updateFields = {};
445
445
  return _this;
446
446
  }
@@ -470,7 +470,7 @@ var MysqlUpdater = /** @class */ (function (_super) {
470
470
  Object.defineProperty(MysqlUpdater.prototype, "sql", {
471
471
  get: function () {
472
472
  var _a = this, updateStat = _a.updateStat, selectStat = _a.selectStat, optionStat = _a.optionStat;
473
- var target = "UPDATE ".concat(this._tableName);
473
+ var target = "UPDATE ".concat(this.table);
474
474
  if (selectStat.sql && updateStat.sql) {
475
475
  target += updateStat.sql;
476
476
  target += selectStat.sql;
package/dist/index.js CHANGED
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
3
  if (k2 === undefined) k2 = k;
15
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -24,67 +13,17 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
24
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
25
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
26
15
  };
27
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
28
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
29
- return new (P || (P = Promise))(function (resolve, reject) {
30
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
31
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
32
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
33
- step((generator = generator.apply(thisArg, _arguments || [])).next());
34
- });
35
- };
36
- var __generator = (this && this.__generator) || function (thisArg, body) {
37
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
38
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
39
- function verb(n) { return function (v) { return step([n, v]); }; }
40
- function step(op) {
41
- if (f) throw new TypeError("Generator is already executing.");
42
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
43
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
44
- if (y = 0, t) op = [op[0] & 2, t.value];
45
- switch (op[0]) {
46
- case 0: case 1: t = op; break;
47
- case 4: _.label++; return { value: op[1], done: false };
48
- case 5: _.label++; y = op[1]; op = [0]; continue;
49
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
50
- default:
51
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
52
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
53
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
54
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
55
- if (t[2]) _.ops.pop();
56
- _.trys.pop(); continue;
57
- }
58
- op = body.call(thisArg, _);
59
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
60
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
61
- }
62
- };
63
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
64
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
65
18
  };
66
19
  Object.defineProperty(exports, "__esModule", { value: true });
67
- exports.CreateMysql = CreateMysql;
20
+ exports.setup = setup;
68
21
  var promise_1 = __importDefault(require("mysql2/promise")); // 使用 Promise 接口
69
22
  __exportStar(require("./helper"), exports);
70
23
  __exportStar(require("./meta"), exports);
71
24
  __exportStar(require("./interface"), exports);
72
25
  __exportStar(require("./utils"), exports);
73
- function CreateMysql(props) {
74
- return {
75
- setup: function (database) {
76
- return __awaiter(this, void 0, void 0, function () {
77
- return __generator(this, function (_a) {
78
- // @ts-ignore
79
- if (!global.$MysqlDb) {
80
- // @ts-ignore
81
- global.$MysqlDb = {};
82
- }
83
- // @ts-ignore
84
- global.$MysqlDb[database] = promise_1.default.createPool(__assign(__assign({}, props), { database: database }));
85
- return [2 /*return*/];
86
- });
87
- });
88
- },
89
- };
26
+ function setup(props) {
27
+ // @ts-ignore
28
+ global.$MysqlPool = promise_1.default.createPool(props);
90
29
  }
package/dist/meta.js CHANGED
@@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.MysqlDbSchema = void 0;
40
+ exports.MysqlRegister = MysqlRegister;
40
41
  var helper_1 = require("./helper");
41
42
  var utils_1 = require("./utils");
42
43
  /**
@@ -44,9 +45,8 @@ var utils_1 = require("./utils");
44
45
  * 使用$toMap时 不返回的字段名前面需要加$
45
46
  */
46
47
  var MysqlDbSchema = /** @class */ (function () {
47
- function MysqlDbSchema($database, $table, $mapExFields) {
48
+ function MysqlDbSchema($table, $mapExFields) {
48
49
  if ($mapExFields === void 0) { $mapExFields = []; }
49
- this.$database = $database;
50
50
  this.$table = $table;
51
51
  this.$mapExFields = $mapExFields;
52
52
  this.id = "";
@@ -103,7 +103,7 @@ var MysqlDbSchema = /** @class */ (function () {
103
103
  return __generator(this, function (_a) {
104
104
  switch (_a.label) {
105
105
  case 0:
106
- selector = new helper_1.MysqlSelector(this.$database, this.$table);
106
+ selector = new helper_1.MysqlSelector(this.$table);
107
107
  return [4 /*yield*/, selector.getById(this.id)];
108
108
  case 1:
109
109
  res = _a.sent();
@@ -123,7 +123,7 @@ var MysqlDbSchema = /** @class */ (function () {
123
123
  return __generator(this, function (_a) {
124
124
  switch (_a.label) {
125
125
  case 0:
126
- inserter = new helper_1.MysqlInserter(this.$database, this.$table, this.$fields);
126
+ inserter = new helper_1.MysqlInserter(this.$table);
127
127
  inserter.push(this.$toJson);
128
128
  if (!uniqueKey) return [3 /*break*/, 2];
129
129
  return [4 /*yield*/, inserter.pool.query("SELECT 1 FROM ".concat(this.$table, " WHERE ").concat(uniqueKey, " = ? LIMIT 1"), [this.$toJson[uniqueKey]])];
@@ -155,7 +155,7 @@ var MysqlDbSchema = /** @class */ (function () {
155
155
  return __generator(this, function (_a) {
156
156
  switch (_a.label) {
157
157
  case 0:
158
- deleter = new helper_1.MysqlDeleter(this.$database, this.$table);
158
+ deleter = new helper_1.MysqlDeleter(this.$table);
159
159
  return [4 /*yield*/, this.$get()];
160
160
  case 1:
161
161
  user = _a.sent();
@@ -173,7 +173,7 @@ var MysqlDbSchema = /** @class */ (function () {
173
173
  return __generator(this, function (_a) {
174
174
  switch (_a.label) {
175
175
  case 0:
176
- updater = new helper_1.MysqlUpdater(this.$database, this.$table);
176
+ updater = new helper_1.MysqlUpdater(this.$table);
177
177
  return [4 /*yield*/, this.$get()];
178
178
  case 1:
179
179
  user = _a.sent();
@@ -198,3 +198,16 @@ var MysqlDbSchema = /** @class */ (function () {
198
198
  return MysqlDbSchema;
199
199
  }());
200
200
  exports.MysqlDbSchema = MysqlDbSchema;
201
+ function MysqlRegister() {
202
+ return function (Model) {
203
+ var target = new Model();
204
+ var json = Object.keys(target).reduce(function (item, key) {
205
+ if (!key.startsWith("$") &&
206
+ Object.prototype.hasOwnProperty.call(target, key)) {
207
+ item[key] = target[key];
208
+ }
209
+ return item;
210
+ }, {});
211
+ utils_1.Parser.createTableBy(target.$table, json);
212
+ };
213
+ }
package/dist/utils.js CHANGED
@@ -1,11 +1,47 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
3
39
  exports.Parser = void 0;
4
40
  exports.Parser = {
5
41
  easyDate: function (date, format) {
6
42
  if (date === void 0) { date = new Date(); }
7
- if (format === void 0) { format = 'YYYY-MM-DD HH:mm:ss'; }
8
- var pad = function (num) { return num.toString().padStart(2, '0'); };
43
+ if (format === void 0) { format = "YYYY-MM-DD HH:mm:ss"; }
44
+ var pad = function (num) { return num.toString().padStart(2, "0"); };
9
45
  var year = date.getFullYear();
10
46
  var month = pad(date.getMonth() + 1);
11
47
  var day = pad(date.getDate());
@@ -13,12 +49,12 @@ exports.Parser = {
13
49
  var minutes = pad(date.getMinutes());
14
50
  var seconds = pad(date.getSeconds());
15
51
  return format
16
- .replace('YYYY', year.toString())
17
- .replace('MM', month)
18
- .replace('DD', day)
19
- .replace('HH', hours)
20
- .replace('mm', minutes)
21
- .replace('ss', seconds);
52
+ .replace("YYYY", year.toString())
53
+ .replace("MM", month)
54
+ .replace("DD", day)
55
+ .replace("HH", hours)
56
+ .replace("mm", minutes)
57
+ .replace("ss", seconds);
22
58
  },
23
59
  toDbName: function (str) {
24
60
  return str.replace(/[A-Z]/g, function (letter) { return "_".concat(letter.toLowerCase()); });
@@ -26,23 +62,86 @@ exports.Parser = {
26
62
  toFieldName: function (str) {
27
63
  var words = str.split(/[-_\s]+/);
28
64
  if (!words.length)
29
- return '';
65
+ return "";
30
66
  var firstWord = words[0].toLowerCase();
31
67
  var restWords = words
32
68
  .slice(1)
33
69
  .map(function (word) { return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(); });
34
- return firstWord + restWords.join('');
70
+ return firstWord + restWords.join("");
35
71
  },
36
72
  toValuesOf: function (values) {
37
73
  var items = [];
38
74
  for (var v in values) {
39
75
  items.push(exports.Parser.valueTypeOf(v));
40
76
  }
41
- return "(".concat(items.join(', '), ")");
77
+ return "(".concat(items.join(", "), ")");
42
78
  },
43
79
  valueTypeOf: function (v) {
44
- if (typeof v === 'string')
80
+ if (typeof v === "string")
45
81
  return "'".concat(v, "'");
46
82
  return "".concat(v);
47
83
  },
84
+ createTableBy: function (table, json) {
85
+ return __awaiter(this, void 0, void 0, function () {
86
+ var pool, rows, currentCols, mapKeys, dbKeys, addCols, dropCols, _i, addCols_1, col, type, _a, dropCols_1, col;
87
+ return __generator(this, function (_b) {
88
+ switch (_b.label) {
89
+ case 0:
90
+ pool = global.$MysqlPool;
91
+ return [4 /*yield*/, pool.query("\n CREATE TABLE IF NOT EXISTS `".concat(table, "` (\n id BIGINT AUTO_INCREMENT PRIMARY KEY,\n create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\n )\n "))];
92
+ case 1:
93
+ _b.sent();
94
+ return [4 /*yield*/, pool.query("\n SELECT COLUMN_NAME \n FROM INFORMATION_SCHEMA.COLUMNS \n WHERE TABLE_SCHEMA = DATABASE() \n AND TABLE_NAME = ?", [table])];
95
+ case 2:
96
+ rows = (_b.sent())[0];
97
+ currentCols = rows.map(function (r) { return r.COLUMN_NAME; });
98
+ mapKeys = Object.keys(json);
99
+ dbKeys = mapKeys
100
+ .filter(function (k) { return !["id", "createTime", "updateTime"].includes(k); })
101
+ .map(exports.Parser.toDbName);
102
+ addCols = dbKeys.filter(function (k) { return !currentCols.includes(k); });
103
+ dropCols = currentCols.filter(function (c) {
104
+ return !dbKeys.includes(c) && !["id", "create_time", "update_time"].includes(c);
105
+ });
106
+ _i = 0, addCols_1 = addCols;
107
+ _b.label = 3;
108
+ case 3:
109
+ if (!(_i < addCols_1.length)) return [3 /*break*/, 6];
110
+ col = addCols_1[_i];
111
+ type = "VARCHAR(255)";
112
+ if (typeof json[col] === "number")
113
+ type = "INT";
114
+ return [4 /*yield*/, pool.query("ALTER TABLE `".concat(table, "` ADD COLUMN `").concat(col, "` ").concat(type))];
115
+ case 4:
116
+ _b.sent();
117
+ _b.label = 5;
118
+ case 5:
119
+ _i++;
120
+ return [3 /*break*/, 3];
121
+ case 6:
122
+ _a = 0, dropCols_1 = dropCols;
123
+ _b.label = 7;
124
+ case 7:
125
+ if (!(_a < dropCols_1.length)) return [3 /*break*/, 10];
126
+ col = dropCols_1[_a];
127
+ return [4 /*yield*/, pool.query("ALTER TABLE `".concat(table, "` DROP COLUMN `").concat(col, "`"))];
128
+ case 8:
129
+ _b.sent();
130
+ _b.label = 9;
131
+ case 9:
132
+ _a++;
133
+ return [3 /*break*/, 7];
134
+ case 10:
135
+ // @ts-ignore
136
+ this.$MysqlTable[table] = {
137
+ fields: mapKeys,
138
+ };
139
+ return [4 /*yield*/, pool.end()];
140
+ case 11:
141
+ _b.sent();
142
+ return [2 /*return*/];
143
+ }
144
+ });
145
+ });
146
+ },
48
147
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rdyl/node-mysql",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
package/types/helper.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import mysql from "mysql2/promise";
2
2
  import { SortKey, SelectOption, OptionsType } from "./interface";
3
3
  declare class BaseHelper {
4
- _tableName: string;
4
+ table: string;
5
5
  pool: mysql.Pool;
6
- constructor(db: string, _tableName: string);
6
+ constructor(table: string);
7
7
  selects: SelectOption[];
8
8
  options: OptionsType;
9
9
  get selectStat(): {
@@ -20,7 +20,7 @@ declare class BaseHelper {
20
20
  }
21
21
  /** @description 查询数据 */
22
22
  export declare class MysqlSelector<T = object> extends BaseHelper {
23
- constructor(d: string, t: string);
23
+ constructor(d: string);
24
24
  get sql(): string;
25
25
  get countSql(): string;
26
26
  total(): Promise<number>;
@@ -42,14 +42,14 @@ export declare class MysqlSelector<T = object> extends BaseHelper {
42
42
  export declare class MysqlInserter extends BaseHelper {
43
43
  values: Array<unknown[]>;
44
44
  fields: string[];
45
- constructor(d: string, t: string, fields?: string[]);
45
+ constructor(t: string);
46
46
  get sql(): string;
47
47
  push(...arr: Record<string, unknown>[]): void;
48
48
  result(): Promise<number[]>;
49
49
  }
50
50
  /** @description 删除数据 */
51
51
  export declare class MysqlDeleter extends BaseHelper {
52
- constructor(d: string, t: string);
52
+ constructor(t: string);
53
53
  get sql(): string;
54
54
  /** @根据id删除 */
55
55
  removeById(value: number | string): Promise<"ok" | "fail">;
@@ -57,7 +57,7 @@ export declare class MysqlDeleter extends BaseHelper {
57
57
  }
58
58
  /** @description 更新数据 */
59
59
  export declare class MysqlUpdater extends BaseHelper {
60
- constructor(d: string, t: string);
60
+ constructor(t: string);
61
61
  updateFields: Record<string, unknown>;
62
62
  get updateStat(): {
63
63
  sql: string;
package/types/index.d.ts CHANGED
@@ -3,6 +3,4 @@ export * from "./helper";
3
3
  export * from "./meta";
4
4
  export * from "./interface";
5
5
  export * from "./utils";
6
- export declare function CreateMysql(props: mysql.PoolOptions): {
7
- setup(database: string): Promise<void>;
8
- };
6
+ export declare function setup(props: mysql.PoolOptions): void;
package/types/meta.d.ts CHANGED
@@ -3,13 +3,12 @@
3
3
  * 使用$toMap时 不返回的字段名前面需要加$
4
4
  */
5
5
  export declare class MysqlDbSchema implements MysqlDbBaseType {
6
- $database: string;
7
- $table: string;
8
- $mapExFields: string[];
6
+ private $table;
7
+ private $mapExFields;
9
8
  id: number | string;
10
9
  createTime: string;
11
10
  updateTime: string;
12
- constructor($database: string, $table: string, $mapExFields?: string[]);
11
+ constructor($table: string, $mapExFields?: string[]);
13
12
  get $toJson(): any;
14
13
  get $toMap(): any;
15
14
  get $fields(): string[];
@@ -19,3 +18,4 @@ export declare class MysqlDbSchema implements MysqlDbBaseType {
19
18
  $remove(): Promise<MysqlDbResultStat>;
20
19
  $update(maps: Record<string, unknown>): Promise<MysqlDbResultStat>;
21
20
  }
21
+ export declare function MysqlRegister(): (Model: any) => void;
package/types/utils.d.ts CHANGED
@@ -4,4 +4,5 @@ export declare const Parser: {
4
4
  toFieldName(str: string): string;
5
5
  toValuesOf(values: unknown[]): string;
6
6
  valueTypeOf(v: unknown): string;
7
+ createTableBy(table: string, json: Record<string, any>): Promise<void>;
7
8
  };