tspace-mysql 1.1.2 → 1.1.4

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.
@@ -31,42 +31,39 @@ var Blueprint = /** @class */ (function () {
31
31
  this.type = '';
32
32
  this.attrbuites = [];
33
33
  }
34
- Blueprint.prototype._addAssignType = function (type) {
35
- if (this.type)
36
- return this;
37
- this.type = type;
38
- return this;
39
- };
40
- Blueprint.prototype._addAssignAttrbuite = function (attrbuite) {
41
- this.attrbuites = __spreadArray(__spreadArray([], __read(this.attrbuites), false), [attrbuite], false);
42
- return this;
43
- };
34
+ /**
35
+ * Assign type 'int' in table
36
+ * @return {this} this
37
+ */
44
38
  Blueprint.prototype.int = function () {
45
39
  this._addAssignType('INT');
46
40
  return this;
47
41
  };
48
42
  /**
49
- * Assign type
50
- * @param {number}
43
+ * Assign type 'TINYINT' in table
44
+ * @param {number} number
45
+ * @return {this} this
51
46
  */
52
- Blueprint.prototype.tinyInt = function (n) {
53
- if (n === void 0) { n = 1; }
54
- this._addAssignType("TINYINT(".concat(n, ")"));
47
+ Blueprint.prototype.tinyInt = function (number) {
48
+ if (number === void 0) { number = 1; }
49
+ this._addAssignType("TINYINT(".concat(number, ")"));
55
50
  return this;
56
51
  };
57
52
  /**
58
- * Assign type
59
- * @param {number}
53
+ * Assign type 'BIGINT' in table
54
+ * @param {number} number [number = 10]
55
+ * @return {this} this
60
56
  */
61
- Blueprint.prototype.bigInt = function (n) {
62
- if (n === void 0) { n = 10; }
63
- this._addAssignType("BIGINT(".concat(n, ")"));
57
+ Blueprint.prototype.bigInt = function (number) {
58
+ if (number === void 0) { number = 10; }
59
+ this._addAssignType("BIGINT(".concat(number, ")"));
64
60
  return this;
65
61
  };
66
62
  /**
67
- * Assign type
63
+ * Assign type 'DOUBLE' in table
68
64
  * @param {number} length between 1-255
69
65
  * @param {number} decimal 0.000...n
66
+ * @return {this} this
70
67
  */
71
68
  Blueprint.prototype.double = function (length, decimal) {
72
69
  if (length === void 0) { length = 0; }
@@ -79,9 +76,10 @@ var Blueprint = /** @class */ (function () {
79
76
  return this;
80
77
  };
81
78
  /**
82
- * Assign type
79
+ * Assign type 'FLOAT' in table
83
80
  * @param {number} length between 1-255
84
81
  * @param {number} decimal 0.000...n
82
+ * @return {this} this
85
83
  */
86
84
  Blueprint.prototype.float = function (length, decimal) {
87
85
  if (length === void 0) { length = 0; }
@@ -94,44 +92,66 @@ var Blueprint = /** @class */ (function () {
94
92
  return this;
95
93
  };
96
94
  /**
97
- * Assign type
98
- * @param {number} length string between 1-255
95
+ * Assign type 'VARCHAR' in table
96
+ * @param {number} length [length = 100] length of string
97
+ * @return {this} this
99
98
  */
100
- Blueprint.prototype.varchar = function (n) {
101
- if (n === void 0) { n = 100; }
102
- if (n > 255)
103
- n = 255;
104
- this._addAssignType("VARCHAR(".concat(n, ")"));
99
+ Blueprint.prototype.varchar = function (length) {
100
+ if (length === void 0) { length = 100; }
101
+ if (length > 255)
102
+ length = 255;
103
+ this._addAssignType("VARCHAR(".concat(length, ")"));
105
104
  return this;
106
105
  };
107
106
  /**
108
- * Assign type
109
- * @param {number} length string between 1-255
107
+ * Assign type 'CHAR' in table
108
+ * @param {number} length [length = 1] length of string
109
+ * @return {this} this
110
110
  */
111
- Blueprint.prototype.char = function (n) {
112
- if (n === void 0) { n = 1; }
113
- this._addAssignType("CHAR(".concat(n, ")"));
111
+ Blueprint.prototype.char = function (length) {
112
+ if (length === void 0) { length = 1; }
113
+ this._addAssignType("CHAR(".concat(length, ")"));
114
114
  return this;
115
115
  };
116
+ /**
117
+ * Assign type 'LONGTEXT' in table
118
+ * @return {this} this
119
+ */
116
120
  Blueprint.prototype.longText = function () {
117
121
  this._addAssignType("LONGTEXT");
118
122
  return this;
119
123
  };
124
+ /**
125
+ * Assign type 'MEDIUMTEXT' in table
126
+ * @param {number} length [length = 1] length of string
127
+ * @return {this} this
128
+ */
120
129
  Blueprint.prototype.mediumText = function () {
121
130
  this._addAssignType("MEDIUMTEXT");
122
131
  return this;
123
132
  };
133
+ /**
134
+ * Assign type 'TINYTEXT' in table
135
+ * @param {number} length [length = 1] length of string
136
+ * @return {this} this
137
+ */
124
138
  Blueprint.prototype.tinyText = function () {
125
139
  this._addAssignType("TINYTEXT");
126
140
  return this;
127
141
  };
142
+ /**
143
+ * Assign type 'TEXT' in table
144
+ * @param {number} length [length = 1] length of string
145
+ * @return {this} this
146
+ */
128
147
  Blueprint.prototype.text = function () {
129
148
  this._addAssignType("TEXT");
130
149
  return this;
131
150
  };
132
151
  /**
133
- * Assign type
134
- * @param {...string} enum n1, n2, n3, ...n
152
+ * Assign type 'ENUM'
153
+ * @param {...string} enums n1, n2, n3, ...n
154
+ * @return {this} this
135
155
  */
136
156
  Blueprint.prototype.enum = function () {
137
157
  var enums = [];
@@ -141,54 +161,105 @@ var Blueprint = /** @class */ (function () {
141
161
  this._addAssignType("ENUM('".concat(enums, "')"));
142
162
  return this;
143
163
  };
164
+ /**
165
+ * Assign type 'DATE' in table
166
+ * @return {this} this
167
+ */
144
168
  Blueprint.prototype.date = function () {
145
169
  this._addAssignType("DATE");
146
170
  return this;
147
171
  };
172
+ /**
173
+ * Assign type 'DATETIME' in table
174
+ * @return {this} this
175
+ */
148
176
  Blueprint.prototype.dateTime = function () {
149
177
  this._addAssignType("DATETIME");
150
178
  return this;
151
179
  };
180
+ /**
181
+ * Assign type 'TIMESTAMP' in table
182
+ * @return {this} this
183
+ */
152
184
  Blueprint.prototype.timestamp = function () {
153
185
  this._addAssignType("TIMESTAMP");
154
186
  return this;
155
187
  };
188
+ /**
189
+ * Assign type 'UNSIGNED' in table
190
+ * @return {this} this
191
+ */
156
192
  Blueprint.prototype.unsigned = function () {
157
193
  this._addAssignAttrbuite("UNSIGNED");
158
194
  return this;
159
195
  };
196
+ /**
197
+ * Assign type 'UNIQUE' in table
198
+ * @return {this} this
199
+ */
160
200
  Blueprint.prototype.unique = function () {
161
201
  this._addAssignAttrbuite("UNIQUE");
162
202
  return this;
163
203
  };
204
+ /**
205
+ * Assign type 'NULL' in table
206
+ * @return {this} this
207
+ */
164
208
  Blueprint.prototype.null = function () {
165
209
  this._addAssignAttrbuite("NULL");
166
210
  return this;
167
211
  };
212
+ /**
213
+ * Assign type 'NOT NULL' in table
214
+ * @return {this} this
215
+ */
168
216
  Blueprint.prototype.notNull = function () {
169
217
  this._addAssignAttrbuite("NOT NULL");
170
218
  return this;
171
219
  };
220
+ /**
221
+ * Assign type 'PRIMARY KEY' in table
222
+ * @return {this} this
223
+ */
172
224
  Blueprint.prototype.primary = function () {
173
225
  this._addAssignAttrbuite("PRIMARY KEY");
174
226
  return this;
175
227
  };
176
228
  /**
177
- * Assign attrbuites
178
- * @param {string | number} default value
229
+ * Assign attrbuites 'default' in table
230
+ * @param {string | number} n default value
231
+ * @return {this} this
179
232
  */
180
233
  Blueprint.prototype.default = function (n) {
181
234
  this._addAssignAttrbuite("DEFAULT '".concat(n, "'"));
182
235
  return this;
183
236
  };
184
- Blueprint.prototype.defaultTimestamp = function () {
237
+ /**
238
+ * Assign attrbuites 'default currentTimestamp' in table
239
+ * @return {this} this
240
+ */
241
+ Blueprint.prototype.currentTimestamp = function () {
185
242
  this._addAssignAttrbuite("DEFAULT CURRENT_TIMESTAMP");
186
243
  return this;
187
244
  };
245
+ /**
246
+ * Assign attrbuites 'autoIncrement' in table
247
+ * @return {this} this
248
+ */
188
249
  Blueprint.prototype.autoIncrement = function () {
189
250
  this._addAssignAttrbuite("AUTO_INCREMENT");
190
251
  return this;
191
252
  };
253
+ Blueprint.prototype._addAssignType = function (type) {
254
+ if (this.type)
255
+ return this;
256
+ this.type = type;
257
+ return this;
258
+ };
259
+ Blueprint.prototype._addAssignAttrbuite = function (attrbuite) {
260
+ this.attrbuites = __spreadArray(__spreadArray([], __read(this.attrbuites), false), [attrbuite], false);
261
+ return this;
262
+ };
192
263
  return Blueprint;
193
264
  }());
194
265
  exports.Blueprint = Blueprint;
@@ -1,6 +1,6 @@
1
1
  import { AbstractDB } from './AbstractDB';
2
+ import { ConnectionTransaction } from '../connection';
2
3
  declare class DB extends AbstractDB {
3
- [x: string]: any;
4
4
  constructor(table?: string);
5
5
  /**
6
6
  * Assign table name
@@ -9,10 +9,60 @@ declare class DB extends AbstractDB {
9
9
  */
10
10
  table(table: string): this;
11
11
  /**
12
- * transaction query rollback & commit
13
- * @return {promise<any>}
12
+ * cases query
13
+ * @param {array} cases array
14
+ * @return {string} string
14
15
  */
15
- beginTransaction(): Promise<any>;
16
+ caseUpdate(cases: any[]): string;
17
+ /**
18
+ * generate UUID
19
+ * @return {string} string
20
+ */
21
+ generateUUID(): string;
22
+ /**
23
+ * Get a connection
24
+ * @return {ConnectionTransaction}
25
+ * @type {object} connection
26
+ * @property {function} connection.query - execute query sql then release connection to pool
27
+ * @property {function} connection.startTransaction - start transaction of query
28
+ * @property {function} connection.commit - commit transaction of query
29
+ * @property {function} connection.rollback - rollback transaction of query
30
+ */
31
+ beginTransaction(): Promise<ConnectionTransaction>;
32
+ /**
33
+ * Assign table name
34
+ * @static
35
+ * @param {string} table table name
36
+ * @return {DB} DB
37
+ */
38
+ static table(table: string): DB;
39
+ /**
40
+ * select by cases
41
+ * @static
42
+ * @param {array} cases array object
43
+ * @return {this}
44
+ */
45
+ static caseUpdate(cases: {
46
+ when: string;
47
+ then: string;
48
+ }[]): string;
49
+ /**
50
+ * generate UUID
51
+ * @static
52
+ * @return {string} string
53
+ */
54
+ static generateUUID(): string;
55
+ /**
56
+ * Get a connection
57
+ * @static
58
+ * @return {ConnectionTransaction}
59
+ * @type {object} connection
60
+ * @property {function} connection.query - execute query sql then release connection to pool
61
+ * @property {function} connection.startTransaction - start transaction of query
62
+ * @property {function} connection.commit - commit transaction of query
63
+ * @property {function} connection.rollback - rollback transaction of query
64
+ */
65
+ static beginTransaction(): Promise<ConnectionTransaction>;
16
66
  private _initialDB;
17
67
  private _setupDB;
18
68
  }
@@ -72,6 +72,31 @@ var __values = (this && this.__values) || function(o) {
72
72
  };
73
73
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
74
74
  };
75
+ var __read = (this && this.__read) || function (o, n) {
76
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
77
+ if (!m) return o;
78
+ var i = m.call(o), r, ar = [], e;
79
+ try {
80
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
81
+ }
82
+ catch (error) { e = { error: error }; }
83
+ finally {
84
+ try {
85
+ if (r && !r.done && (m = i["return"])) m.call(i);
86
+ }
87
+ finally { if (e) throw e.error; }
88
+ }
89
+ return ar;
90
+ };
91
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
92
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
93
+ if (ar || !(i in from)) {
94
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
95
+ ar[i] = from[i];
96
+ }
97
+ }
98
+ return to.concat(ar || Array.prototype.slice.call(from));
99
+ };
75
100
  Object.defineProperty(exports, "__esModule", { value: true });
76
101
  exports.DB = void 0;
77
102
  var AbstractDB_1 = require("./AbstractDB");
@@ -97,64 +122,149 @@ var DB = /** @class */ (function (_super) {
97
122
  return this;
98
123
  };
99
124
  /**
100
- * transaction query rollback & commit
101
- * @return {promise<any>}
125
+ * cases query
126
+ * @param {array} cases array
127
+ * @return {string} string
128
+ */
129
+ DB.prototype.caseUpdate = function (cases) {
130
+ var e_1, _a;
131
+ var query = [];
132
+ try {
133
+ for (var cases_1 = __values(cases), cases_1_1 = cases_1.next(); !cases_1_1.done; cases_1_1 = cases_1.next()) {
134
+ var c = cases_1_1.value;
135
+ if (c.when == null)
136
+ throw new Error("can't find when condition");
137
+ if (c.then == null)
138
+ throw new Error("can't find then condition");
139
+ query = __spreadArray(__spreadArray([], __read(query), false), [
140
+ "".concat(this.$constants('WHEN'), " ").concat(c.when, " ").concat(this.$constants('THEN'), " ").concat(c.then)
141
+ ], false);
142
+ }
143
+ }
144
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
145
+ finally {
146
+ try {
147
+ if (cases_1_1 && !cases_1_1.done && (_a = cases_1.return)) _a.call(cases_1);
148
+ }
149
+ finally { if (e_1) throw e_1.error; }
150
+ }
151
+ return [
152
+ this.$constants('RAW'),
153
+ this.$constants('CASE'),
154
+ query.join(' '),
155
+ this.$constants('END')
156
+ ].join(' ');
157
+ };
158
+ /**
159
+ * generate UUID
160
+ * @return {string} string
161
+ */
162
+ DB.prototype.generateUUID = function () {
163
+ return this.$utils.generateUUID();
164
+ };
165
+ /**
166
+ * Get a connection
167
+ * @return {ConnectionTransaction}
168
+ * @type {object} connection
169
+ * @property {function} connection.query - execute query sql then release connection to pool
170
+ * @property {function} connection.startTransaction - start transaction of query
171
+ * @property {function} connection.commit - commit transaction of query
172
+ * @property {function} connection.rollback - rollback transaction of query
102
173
  */
103
174
  DB.prototype.beginTransaction = function () {
104
175
  return __awaiter(this, void 0, void 0, function () {
105
- var transaction;
106
- var _this = this;
176
+ var pool;
177
+ return __generator(this, function (_a) {
178
+ switch (_a.label) {
179
+ case 0: return [4 /*yield*/, this.$pool.load()];
180
+ case 1:
181
+ pool = _a.sent();
182
+ return [4 /*yield*/, pool.connection()];
183
+ case 2: return [2 /*return*/, _a.sent()];
184
+ }
185
+ });
186
+ });
187
+ };
188
+ /**
189
+ * Assign table name
190
+ * @static
191
+ * @param {string} table table name
192
+ * @return {DB} DB
193
+ */
194
+ DB.table = function (table) {
195
+ var self = new this();
196
+ self.$db.set('SELECT', "".concat(self.$constants('SELECT'), " *"));
197
+ self.$db.set('TABLE_NAME', "`".concat(table, "`"));
198
+ self.$db.set('FROM', "".concat(self.$constants('FROM')));
199
+ return self;
200
+ };
201
+ /**
202
+ * select by cases
203
+ * @static
204
+ * @param {array} cases array object
205
+ * @return {this}
206
+ */
207
+ DB.caseUpdate = function (cases) {
208
+ var e_2, _a;
209
+ var self = new this();
210
+ var query = [];
211
+ try {
212
+ for (var cases_2 = __values(cases), cases_2_1 = cases_2.next(); !cases_2_1.done; cases_2_1 = cases_2.next()) {
213
+ var c = cases_2_1.value;
214
+ if (c.when == null)
215
+ throw new Error("can't find when condition");
216
+ if (c.then == null)
217
+ throw new Error("can't find then condition");
218
+ query = __spreadArray(__spreadArray([], __read(query), false), [
219
+ "".concat(self.$constants('WHEN'), " ").concat(c.when, " ").concat(self.$constants('THEN'), " ").concat(c.then)
220
+ ], false);
221
+ }
222
+ }
223
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
224
+ finally {
225
+ try {
226
+ if (cases_2_1 && !cases_2_1.done && (_a = cases_2.return)) _a.call(cases_2);
227
+ }
228
+ finally { if (e_2) throw e_2.error; }
229
+ }
230
+ return [
231
+ self.$constants('RAW'),
232
+ self.$constants('CASE'),
233
+ query.join(' '),
234
+ self.$constants('END'),
235
+ ].join(' ');
236
+ };
237
+ /**
238
+ * generate UUID
239
+ * @static
240
+ * @return {string} string
241
+ */
242
+ DB.generateUUID = function () {
243
+ return new this().$utils.generateUUID();
244
+ };
245
+ /**
246
+ * Get a connection
247
+ * @static
248
+ * @return {ConnectionTransaction}
249
+ * @type {object} connection
250
+ * @property {function} connection.query - execute query sql then release connection to pool
251
+ * @property {function} connection.startTransaction - start transaction of query
252
+ * @property {function} connection.commit - commit transaction of query
253
+ * @property {function} connection.rollback - rollback transaction of query
254
+ */
255
+ DB.beginTransaction = function () {
256
+ return __awaiter(this, void 0, void 0, function () {
257
+ var self, pool;
107
258
  return __generator(this, function (_a) {
108
- transaction = {
109
- rollback: function () { return __awaiter(_this, void 0, void 0, function () {
110
- var transaction, _a, _b, query, e_1_1;
111
- var e_1, _c;
112
- return __generator(this, function (_d) {
113
- switch (_d.label) {
114
- case 0:
115
- transaction = this.$db.get('TRANSACTION');
116
- if (!(transaction === null || transaction === void 0 ? void 0 : transaction.query.length))
117
- return [2 /*return*/, false];
118
- _d.label = 1;
119
- case 1:
120
- _d.trys.push([1, 6, 7, 8]);
121
- _a = __values(transaction.query), _b = _a.next();
122
- _d.label = 2;
123
- case 2:
124
- if (!!_b.done) return [3 /*break*/, 5];
125
- query = _b.value;
126
- if (query.id === '' || query.table === '' || query.id == null || query.table == null) {
127
- return [2 /*return*/, false];
128
- }
129
- return [4 /*yield*/, new DB()
130
- .table(query.table)
131
- .where('id', query.id)
132
- .delete()];
133
- case 3:
134
- _d.sent();
135
- _d.label = 4;
136
- case 4:
137
- _b = _a.next();
138
- return [3 /*break*/, 2];
139
- case 5: return [3 /*break*/, 8];
140
- case 6:
141
- e_1_1 = _d.sent();
142
- e_1 = { error: e_1_1 };
143
- return [3 /*break*/, 8];
144
- case 7:
145
- try {
146
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
147
- }
148
- finally { if (e_1) throw e_1.error; }
149
- return [7 /*endfinally*/];
150
- case 8: return [2 /*return*/, true];
151
- }
152
- });
153
- }); },
154
- query: []
155
- };
156
- this.$db.set('TRANSACTION', transaction);
157
- return [2 /*return*/, transaction];
259
+ switch (_a.label) {
260
+ case 0:
261
+ self = new this();
262
+ return [4 /*yield*/, self.$pool.load()];
263
+ case 1:
264
+ pool = _a.sent();
265
+ return [4 /*yield*/, pool.connection()];
266
+ case 2: return [2 /*return*/, _a.sent()];
267
+ }
158
268
  });
159
269
  });
160
270
  };
@@ -177,6 +287,10 @@ var DB = /** @class */ (function (_super) {
177
287
  throw new Error("can't set this [".concat(key, "]"));
178
288
  db.set(key, value);
179
289
  return;
290
+ },
291
+ clone: function (data) {
292
+ db = new Map(Object.entries(__assign({}, data)));
293
+ return;
180
294
  }
181
295
  };
182
296
  };