tspace-mysql 1.1.2 → 1.1.3
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/dist/cli/index.js +23 -24
- package/dist/cli/migrate/make.js +18 -41
- package/dist/cli/models/make.js +18 -18
- package/dist/cli/models/model.js +27 -2
- package/dist/cli/tables/make.js +10 -10
- package/dist/cli/tables/table.js +22 -2
- package/dist/lib/config/env.d.ts +6 -0
- package/dist/lib/config/env.js +16 -10
- package/dist/lib/connection/index.d.ts +29 -8
- package/dist/lib/connection/index.js +111 -55
- package/dist/lib/constants/index.js +7 -5
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +2 -2
- package/dist/lib/tspace/AbstractDB.js +3 -23
- package/dist/lib/tspace/AbstractDatabase.d.ts +9 -4
- package/dist/lib/tspace/AbstractDatabase.js +28 -31
- package/dist/lib/tspace/AbstractModel.d.ts +30 -16
- package/dist/lib/tspace/AbstractModel.js +3 -23
- package/dist/lib/tspace/Blueprint.d.ts +92 -21
- package/dist/lib/tspace/Blueprint.js +171 -140
- package/dist/lib/tspace/DB.d.ts +27 -4
- package/dist/lib/tspace/DB.js +66 -158
- package/dist/lib/tspace/Database.d.ts +100 -51
- package/dist/lib/tspace/Database.js +1335 -1911
- package/dist/lib/tspace/Interface.d.ts +8 -8
- package/dist/lib/tspace/Logger.js +19 -19
- package/dist/lib/tspace/Model.d.ts +168 -132
- package/dist/lib/tspace/Model.js +1467 -2081
- package/dist/lib/tspace/ProxyHandler.js +15 -26
- package/dist/lib/tspace/Schema.js +25 -117
- package/dist/lib/tspace/index.js +4 -4
- package/dist/lib/utils/index.d.ts +4 -3
- package/dist/lib/utils/index.js +87 -112
- package/package.json +1 -1
|
@@ -1,195 +1,226 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
3
|
exports.Blueprint = void 0;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
};
|
|
44
|
-
Blueprint.prototype.int = function () {
|
|
4
|
+
class Blueprint {
|
|
5
|
+
type = '';
|
|
6
|
+
attrbuites = [];
|
|
7
|
+
/**
|
|
8
|
+
* Assign type 'int' in table
|
|
9
|
+
* @return {this} this
|
|
10
|
+
*/
|
|
11
|
+
int() {
|
|
45
12
|
this._addAssignType('INT');
|
|
46
13
|
return this;
|
|
47
|
-
}
|
|
14
|
+
}
|
|
48
15
|
/**
|
|
49
|
-
* Assign type
|
|
50
|
-
* @param {number}
|
|
16
|
+
* Assign type 'TINYINT' in table
|
|
17
|
+
* @param {number} number
|
|
18
|
+
* @return {this} this
|
|
51
19
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this._addAssignType("TINYINT(".concat(n, ")"));
|
|
20
|
+
tinyInt(number = 1) {
|
|
21
|
+
this._addAssignType(`TINYINT(${number})`);
|
|
55
22
|
return this;
|
|
56
|
-
}
|
|
23
|
+
}
|
|
57
24
|
/**
|
|
58
|
-
* Assign type
|
|
59
|
-
* @param {number}
|
|
25
|
+
* Assign type 'BIGINT' in table
|
|
26
|
+
* @param {number} number [number = 10]
|
|
27
|
+
* @return {this} this
|
|
60
28
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this._addAssignType("BIGINT(".concat(n, ")"));
|
|
29
|
+
bigInt(number = 10) {
|
|
30
|
+
this._addAssignType(`BIGINT(${number})`);
|
|
64
31
|
return this;
|
|
65
|
-
}
|
|
32
|
+
}
|
|
66
33
|
/**
|
|
67
|
-
* Assign type
|
|
34
|
+
* Assign type 'DOUBLE' in table
|
|
68
35
|
* @param {number} length between 1-255
|
|
69
36
|
* @param {number} decimal 0.000...n
|
|
37
|
+
* @return {this} this
|
|
70
38
|
*/
|
|
71
|
-
|
|
72
|
-
if (length === void 0) { length = 0; }
|
|
73
|
-
if (decimal === void 0) { decimal = 0; }
|
|
39
|
+
double(length = 0, decimal = 0) {
|
|
74
40
|
if (!length || !decimal) {
|
|
75
|
-
this._addAssignType(
|
|
41
|
+
this._addAssignType(`DOUBLE`);
|
|
76
42
|
return this;
|
|
77
43
|
}
|
|
78
|
-
this._addAssignType(
|
|
44
|
+
this._addAssignType(`DOUBLE(${length},${decimal})`);
|
|
79
45
|
return this;
|
|
80
|
-
}
|
|
46
|
+
}
|
|
81
47
|
/**
|
|
82
|
-
* Assign type
|
|
48
|
+
* Assign type 'FLOAT' in table
|
|
83
49
|
* @param {number} length between 1-255
|
|
84
50
|
* @param {number} decimal 0.000...n
|
|
51
|
+
* @return {this} this
|
|
85
52
|
*/
|
|
86
|
-
|
|
87
|
-
if (length === void 0) { length = 0; }
|
|
88
|
-
if (decimal === void 0) { decimal = 0; }
|
|
53
|
+
float(length = 0, decimal = 0) {
|
|
89
54
|
if (!length || !decimal) {
|
|
90
|
-
this._addAssignType(
|
|
55
|
+
this._addAssignType(`FLOAT`);
|
|
91
56
|
return this;
|
|
92
57
|
}
|
|
93
|
-
this._addAssignType(
|
|
58
|
+
this._addAssignType(`FLOAT(${length},${decimal})`);
|
|
94
59
|
return this;
|
|
95
|
-
}
|
|
60
|
+
}
|
|
96
61
|
/**
|
|
97
|
-
* Assign type
|
|
98
|
-
* @param {number} length
|
|
62
|
+
* Assign type 'VARCHAR' in table
|
|
63
|
+
* @param {number} length [length = 100] length of string
|
|
64
|
+
* @return {this} this
|
|
99
65
|
*/
|
|
100
|
-
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this._addAssignType("VARCHAR(".concat(n, ")"));
|
|
66
|
+
varchar(length = 100) {
|
|
67
|
+
if (length > 255)
|
|
68
|
+
length = 255;
|
|
69
|
+
this._addAssignType(`VARCHAR(${length})`);
|
|
105
70
|
return this;
|
|
106
|
-
}
|
|
71
|
+
}
|
|
107
72
|
/**
|
|
108
|
-
* Assign type
|
|
109
|
-
* @param {number} length
|
|
73
|
+
* Assign type 'CHAR' in table
|
|
74
|
+
* @param {number} length [length = 1] length of string
|
|
75
|
+
* @return {this} this
|
|
110
76
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this._addAssignType("CHAR(".concat(n, ")"));
|
|
77
|
+
char(length = 1) {
|
|
78
|
+
this._addAssignType(`CHAR(${length})`);
|
|
114
79
|
return this;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Assign type 'LONGTEXT' in table
|
|
83
|
+
* @return {this} this
|
|
84
|
+
*/
|
|
85
|
+
longText() {
|
|
86
|
+
this._addAssignType(`LONGTEXT`);
|
|
118
87
|
return this;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Assign type 'MEDIUMTEXT' in table
|
|
91
|
+
* @param {number} length [length = 1] length of string
|
|
92
|
+
* @return {this} this
|
|
93
|
+
*/
|
|
94
|
+
mediumText() {
|
|
95
|
+
this._addAssignType(`MEDIUMTEXT`);
|
|
122
96
|
return this;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Assign type 'TINYTEXT' in table
|
|
100
|
+
* @param {number} length [length = 1] length of string
|
|
101
|
+
* @return {this} this
|
|
102
|
+
*/
|
|
103
|
+
tinyText() {
|
|
104
|
+
this._addAssignType(`TINYTEXT`);
|
|
126
105
|
return this;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Assign type 'TEXT' in table
|
|
109
|
+
* @param {number} length [length = 1] length of string
|
|
110
|
+
* @return {this} this
|
|
111
|
+
*/
|
|
112
|
+
text() {
|
|
113
|
+
this._addAssignType(`TEXT`);
|
|
130
114
|
return this;
|
|
131
|
-
}
|
|
115
|
+
}
|
|
132
116
|
/**
|
|
133
|
-
* Assign type
|
|
134
|
-
* @param {...string}
|
|
117
|
+
* Assign type 'ENUM'
|
|
118
|
+
* @param {...string} enums n1, n2, n3, ...n
|
|
119
|
+
* @return {this} this
|
|
135
120
|
*/
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
121
|
+
enum(...enums) {
|
|
122
|
+
this._addAssignType(`ENUM('${enums}')`);
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Assign type 'DATE' in table
|
|
127
|
+
* @return {this} this
|
|
128
|
+
*/
|
|
129
|
+
date() {
|
|
130
|
+
this._addAssignType(`DATE`);
|
|
142
131
|
return this;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Assign type 'DATETIME' in table
|
|
135
|
+
* @return {this} this
|
|
136
|
+
*/
|
|
137
|
+
dateTime() {
|
|
138
|
+
this._addAssignType(`DATETIME`);
|
|
146
139
|
return this;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Assign type 'TIMESTAMP' in table
|
|
143
|
+
* @return {this} this
|
|
144
|
+
*/
|
|
145
|
+
timestamp() {
|
|
146
|
+
this._addAssignType(`TIMESTAMP`);
|
|
150
147
|
return this;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Assign type 'UNSIGNED' in table
|
|
151
|
+
* @return {this} this
|
|
152
|
+
*/
|
|
153
|
+
unsigned() {
|
|
154
|
+
this._addAssignAttrbuite(`UNSIGNED`);
|
|
154
155
|
return this;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Assign type 'UNIQUE' in table
|
|
159
|
+
* @return {this} this
|
|
160
|
+
*/
|
|
161
|
+
unique() {
|
|
162
|
+
this._addAssignAttrbuite(`UNIQUE`);
|
|
158
163
|
return this;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Assign type 'NULL' in table
|
|
167
|
+
* @return {this} this
|
|
168
|
+
*/
|
|
169
|
+
null() {
|
|
170
|
+
this._addAssignAttrbuite(`NULL`);
|
|
162
171
|
return this;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Assign type 'NOT NULL' in table
|
|
175
|
+
* @return {this} this
|
|
176
|
+
*/
|
|
177
|
+
notNull() {
|
|
178
|
+
this._addAssignAttrbuite(`NOT NULL`);
|
|
166
179
|
return this;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Assign type 'PRIMARY KEY' in table
|
|
183
|
+
* @return {this} this
|
|
184
|
+
*/
|
|
185
|
+
primary() {
|
|
186
|
+
this._addAssignAttrbuite(`PRIMARY KEY`);
|
|
170
187
|
return this;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Assign attrbuites 'default' in table
|
|
191
|
+
* @param {string | number} n default value
|
|
192
|
+
* @return {this} this
|
|
193
|
+
*/
|
|
194
|
+
default(n) {
|
|
195
|
+
this._addAssignAttrbuite(`DEFAULT '${n}'`);
|
|
174
196
|
return this;
|
|
175
|
-
}
|
|
197
|
+
}
|
|
176
198
|
/**
|
|
177
|
-
* Assign attrbuites
|
|
178
|
-
* @
|
|
199
|
+
* Assign attrbuites 'default currentTimestamp' in table
|
|
200
|
+
* @return {this} this
|
|
179
201
|
*/
|
|
180
|
-
|
|
181
|
-
this._addAssignAttrbuite(
|
|
202
|
+
currentTimestamp() {
|
|
203
|
+
this._addAssignAttrbuite(`DEFAULT CURRENT_TIMESTAMP`);
|
|
182
204
|
return this;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Assign attrbuites 'autoIncrement' in table
|
|
208
|
+
* @return {this} this
|
|
209
|
+
*/
|
|
210
|
+
autoIncrement() {
|
|
211
|
+
this._addAssignAttrbuite(`AUTO_INCREMENT`);
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
_addAssignType(type) {
|
|
215
|
+
if (this.type)
|
|
216
|
+
return this;
|
|
217
|
+
this.type = type;
|
|
186
218
|
return this;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
this.
|
|
219
|
+
}
|
|
220
|
+
_addAssignAttrbuite(attrbuite) {
|
|
221
|
+
this.attrbuites = [...this.attrbuites, attrbuite];
|
|
190
222
|
return this;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
}());
|
|
223
|
+
}
|
|
224
|
+
}
|
|
194
225
|
exports.Blueprint = Blueprint;
|
|
195
226
|
exports.default = Blueprint;
|
package/dist/lib/tspace/DB.d.ts
CHANGED
|
@@ -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,33 @@ declare class DB extends AbstractDB {
|
|
|
9
9
|
*/
|
|
10
10
|
table(table: string): this;
|
|
11
11
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
* Get a connection
|
|
13
|
+
* @return {ConnectionTransaction}
|
|
14
|
+
* @type {object} connection
|
|
15
|
+
* @property {function} connection.query - execute query sql then release connection to pool
|
|
16
|
+
* @property {function} connection.startTransaction - start transaction of query
|
|
17
|
+
* @property {function} connection.commit - commit transaction of query
|
|
18
|
+
* @property {function} connection.rollback - rollback transaction of query
|
|
19
|
+
*/
|
|
20
|
+
beginTransaction(): Promise<ConnectionTransaction>;
|
|
21
|
+
/**
|
|
22
|
+
* Assign table name
|
|
23
|
+
* @static
|
|
24
|
+
* @param {string} table table name
|
|
25
|
+
* @return {DB} DB
|
|
26
|
+
*/
|
|
27
|
+
static table(table: string): DB;
|
|
28
|
+
/**
|
|
29
|
+
* Get a connection
|
|
30
|
+
* @static
|
|
31
|
+
* @return {ConnectionTransaction}
|
|
32
|
+
* @type {object} connection
|
|
33
|
+
* @property {function} connection.query - execute query sql then release connection to pool
|
|
34
|
+
* @property {function} connection.startTransaction - start transaction of query
|
|
35
|
+
* @property {function} connection.commit - commit transaction of query
|
|
36
|
+
* @property {function} connection.rollback - rollback transaction of query
|
|
14
37
|
*/
|
|
15
|
-
beginTransaction(): Promise<
|
|
38
|
+
static beginTransaction(): Promise<ConnectionTransaction>;
|
|
16
39
|
private _initialDB;
|
|
17
40
|
private _setupDB;
|
|
18
41
|
}
|
package/dist/lib/tspace/DB.js
CHANGED
|
@@ -1,186 +1,94 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
38
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
-
function step(op) {
|
|
42
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
-
while (_) try {
|
|
44
|
-
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;
|
|
45
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
-
switch (op[0]) {
|
|
47
|
-
case 0: case 1: t = op; break;
|
|
48
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
-
default:
|
|
52
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
-
if (t[2]) _.ops.pop();
|
|
57
|
-
_.trys.pop(); continue;
|
|
58
|
-
}
|
|
59
|
-
op = body.call(thisArg, _);
|
|
60
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
var __values = (this && this.__values) || function(o) {
|
|
65
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
66
|
-
if (m) return m.call(o);
|
|
67
|
-
if (o && typeof o.length === "number") return {
|
|
68
|
-
next: function () {
|
|
69
|
-
if (o && i >= o.length) o = void 0;
|
|
70
|
-
return { value: o && o[i++], done: !o };
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
74
|
-
};
|
|
75
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
76
3
|
exports.DB = void 0;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
_this._initialDB();
|
|
4
|
+
const AbstractDB_1 = require("./AbstractDB");
|
|
5
|
+
const ProxyHandler_1 = require("./ProxyHandler");
|
|
6
|
+
class DB extends AbstractDB_1.AbstractDB {
|
|
7
|
+
constructor(table) {
|
|
8
|
+
super();
|
|
9
|
+
this._initialDB();
|
|
84
10
|
if (table)
|
|
85
|
-
|
|
86
|
-
return new Proxy(
|
|
11
|
+
this.table(table);
|
|
12
|
+
return new Proxy(this, ProxyHandler_1.proxyHandler);
|
|
87
13
|
}
|
|
88
14
|
/**
|
|
89
15
|
* Assign table name
|
|
90
16
|
* @param {string} table table name
|
|
91
17
|
* @return {this} this
|
|
92
18
|
*/
|
|
93
|
-
|
|
94
|
-
this.$db.set('SELECT',
|
|
95
|
-
this.$db.set('TABLE_NAME',
|
|
96
|
-
this.$db.set('FROM',
|
|
19
|
+
table(table) {
|
|
20
|
+
this.$db.set('SELECT', `${this.$constants('SELECT')} *`);
|
|
21
|
+
this.$db.set('TABLE_NAME', `\`${table}\``);
|
|
22
|
+
this.$db.set('FROM', `${this.$constants('FROM')}`);
|
|
97
23
|
return this;
|
|
98
|
-
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get a connection
|
|
27
|
+
* @return {ConnectionTransaction}
|
|
28
|
+
* @type {object} connection
|
|
29
|
+
* @property {function} connection.query - execute query sql then release connection to pool
|
|
30
|
+
* @property {function} connection.startTransaction - start transaction of query
|
|
31
|
+
* @property {function} connection.commit - commit transaction of query
|
|
32
|
+
* @property {function} connection.rollback - rollback transaction of query
|
|
33
|
+
*/
|
|
34
|
+
async beginTransaction() {
|
|
35
|
+
const pool = await this.$pool.load();
|
|
36
|
+
return await pool.connection();
|
|
37
|
+
}
|
|
99
38
|
/**
|
|
100
|
-
*
|
|
101
|
-
* @
|
|
39
|
+
* Assign table name
|
|
40
|
+
* @static
|
|
41
|
+
* @param {string} table table name
|
|
42
|
+
* @return {DB} DB
|
|
102
43
|
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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];
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
};
|
|
161
|
-
DB.prototype._initialDB = function () {
|
|
44
|
+
static table(table) {
|
|
45
|
+
const self = new this();
|
|
46
|
+
self.$db.set('SELECT', `${self.$constants('SELECT')} *`);
|
|
47
|
+
self.$db.set('TABLE_NAME', `\`${table}\``);
|
|
48
|
+
self.$db.set('FROM', `${self.$constants('FROM')}`);
|
|
49
|
+
return self;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get a connection
|
|
53
|
+
* @static
|
|
54
|
+
* @return {ConnectionTransaction}
|
|
55
|
+
* @type {object} connection
|
|
56
|
+
* @property {function} connection.query - execute query sql then release connection to pool
|
|
57
|
+
* @property {function} connection.startTransaction - start transaction of query
|
|
58
|
+
* @property {function} connection.commit - commit transaction of query
|
|
59
|
+
* @property {function} connection.rollback - rollback transaction of query
|
|
60
|
+
*/
|
|
61
|
+
static async beginTransaction() {
|
|
62
|
+
const self = new this();
|
|
63
|
+
const pool = await self.$pool.load();
|
|
64
|
+
return await pool.connection();
|
|
65
|
+
}
|
|
66
|
+
_initialDB() {
|
|
162
67
|
this.$db = this._setupDB();
|
|
163
68
|
return this;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
69
|
+
}
|
|
70
|
+
_setupDB() {
|
|
71
|
+
let db = new Map(Object.entries({ ...this.$constants('DB') }));
|
|
167
72
|
return {
|
|
168
|
-
get:
|
|
73
|
+
get: (key) => {
|
|
169
74
|
if (key == null)
|
|
170
75
|
return db;
|
|
171
76
|
if (!db.has(key))
|
|
172
|
-
throw new Error(
|
|
77
|
+
throw new Error(`can't get this [${key}]`);
|
|
173
78
|
return db.get(key);
|
|
174
79
|
},
|
|
175
|
-
set:
|
|
80
|
+
set: (key, value) => {
|
|
176
81
|
if (!db.has(key))
|
|
177
|
-
throw new Error(
|
|
82
|
+
throw new Error(`can't set this [${key}]`);
|
|
178
83
|
db.set(key, value);
|
|
179
84
|
return;
|
|
85
|
+
},
|
|
86
|
+
clone: (data) => {
|
|
87
|
+
db = new Map(Object.entries({ ...data }));
|
|
88
|
+
return;
|
|
180
89
|
}
|
|
181
90
|
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
}(AbstractDB_1.AbstractDB));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
185
93
|
exports.DB = DB;
|
|
186
94
|
exports.default = DB;
|