tspace-mysql 1.1.8 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -38
- package/dist/cli/generate/make.d.ts +4 -0
- package/dist/cli/generate/make.js +45 -0
- package/dist/cli/index.js +27 -13
- package/dist/cli/migrate/make.js +5 -4
- package/dist/cli/models/make.d.ts +1 -1
- package/dist/cli/models/make.js +2 -2
- package/dist/cli/models/model.js +3 -4
- package/dist/cli/query/index.d.ts +4 -0
- package/dist/cli/query/index.js +7 -0
- package/dist/lib/connection/index.d.ts +8 -32
- package/dist/lib/connection/index.js +50 -37
- package/dist/lib/connection/options.d.ts +4 -0
- package/dist/lib/{config/env.js → connection/options.js} +10 -7
- package/dist/lib/constants/index.d.ts +2 -2
- package/dist/lib/constants/index.js +14 -11
- package/dist/lib/tspace/AbstractDB.d.ts +2 -0
- package/dist/lib/tspace/AbstractDatabase.d.ts +23 -19
- package/dist/lib/tspace/AbstractDatabase.js +29 -26
- package/dist/lib/tspace/AbstractModel.d.ts +5 -4
- package/dist/lib/tspace/Blueprint.js +4 -2
- package/dist/lib/tspace/DB.d.ts +23 -2
- package/dist/lib/tspace/DB.js +93 -30
- package/dist/lib/tspace/Database.d.ts +26 -13
- package/dist/lib/tspace/Database.js +920 -777
- package/dist/lib/tspace/Interface.d.ts +26 -0
- package/dist/lib/tspace/Logger.js +5 -4
- package/dist/lib/tspace/Model.d.ts +73 -23
- package/dist/lib/tspace/Model.js +1208 -867
- package/dist/lib/tspace/ProxyHandler.d.ts +9 -1
- package/dist/lib/tspace/ProxyHandler.js +8 -9
- package/dist/lib/tspace/Schema.js +35 -22
- package/dist/lib/utils/index.d.ts +0 -1
- package/dist/lib/utils/index.js +15 -44
- package/package.json +4 -2
- package/dist/lib/config/env.d.ts +0 -4
|
@@ -68,6 +68,32 @@ export interface ConnectionOptions {
|
|
|
68
68
|
username: string;
|
|
69
69
|
password: string;
|
|
70
70
|
}
|
|
71
|
+
export interface PoolCallback {
|
|
72
|
+
query: (sql: string, callback: (err: any, result: any) => void) => void;
|
|
73
|
+
release: () => void;
|
|
74
|
+
}
|
|
75
|
+
export interface ConnectionTransaction {
|
|
76
|
+
query: (sql: string) => Promise<any>;
|
|
77
|
+
startTransaction: () => Promise<any>;
|
|
78
|
+
commit: () => Promise<any>;
|
|
79
|
+
rollback: () => Promise<any>;
|
|
80
|
+
}
|
|
81
|
+
export interface Connection {
|
|
82
|
+
query: (sql: string) => Promise<any>;
|
|
83
|
+
connection: () => Promise<ConnectionTransaction>;
|
|
84
|
+
}
|
|
85
|
+
export interface Options {
|
|
86
|
+
[key: string]: any;
|
|
87
|
+
connectionLimit?: number;
|
|
88
|
+
dateStrings?: boolean;
|
|
89
|
+
waitForConnections?: boolean;
|
|
90
|
+
charset?: string;
|
|
91
|
+
host: string;
|
|
92
|
+
port: number;
|
|
93
|
+
database: string;
|
|
94
|
+
user: string;
|
|
95
|
+
password: string;
|
|
96
|
+
}
|
|
71
97
|
export interface Execute {
|
|
72
98
|
sql: string;
|
|
73
99
|
type: string;
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Logger = void 0;
|
|
4
4
|
class Logger {
|
|
5
|
-
SELF;
|
|
6
|
-
PROP = '';
|
|
7
5
|
constructor(self, prop) {
|
|
6
|
+
this.PROP = '';
|
|
8
7
|
this.SELF = self;
|
|
9
8
|
this.PROP = prop;
|
|
10
9
|
return this.initialize();
|
|
11
10
|
}
|
|
12
11
|
initialize() {
|
|
12
|
+
var _a;
|
|
13
13
|
if (this.SELF == null)
|
|
14
14
|
return;
|
|
15
15
|
const runing = this.SELF[this.PROP];
|
|
@@ -27,7 +27,8 @@ class Logger {
|
|
|
27
27
|
'hasMany',
|
|
28
28
|
'belongsToMany',
|
|
29
29
|
'constructor',
|
|
30
|
-
'boot'
|
|
30
|
+
'boot',
|
|
31
|
+
'define'
|
|
31
32
|
];
|
|
32
33
|
const _use = this.PROP.substring(0, 3) !== 'use';
|
|
33
34
|
const _private = this.PROP.charAt(0) !== '_';
|
|
@@ -41,7 +42,7 @@ class Logger {
|
|
|
41
42
|
].every((data) => data === true);
|
|
42
43
|
if (!conditions)
|
|
43
44
|
return;
|
|
44
|
-
return this.SELF.$logger
|
|
45
|
+
return (_a = this.SELF.$logger) === null || _a === void 0 ? void 0 : _a.set(this.PROP);
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
exports.Logger = Logger;
|
|
@@ -16,12 +16,12 @@ declare class Model extends AbstractModel {
|
|
|
16
16
|
protected useRegistry(): this;
|
|
17
17
|
/**
|
|
18
18
|
*
|
|
19
|
-
* Assign
|
|
19
|
+
* Assign primary column in model
|
|
20
20
|
* @return {this} this
|
|
21
21
|
*/
|
|
22
22
|
protected usePrimaryKey(primary: string): this;
|
|
23
23
|
/**
|
|
24
|
-
* Assign
|
|
24
|
+
* Assign generate uuid when creating in model
|
|
25
25
|
* @param {string?} column [column=uuid] make new name column for custom column replace uuid with this
|
|
26
26
|
* @return {this} this
|
|
27
27
|
*/
|
|
@@ -87,10 +87,23 @@ declare class Model extends AbstractModel {
|
|
|
87
87
|
/**
|
|
88
88
|
*
|
|
89
89
|
* Clone instance of model
|
|
90
|
-
* @
|
|
90
|
+
* @param {Model} instance instance of model
|
|
91
91
|
* @return {this} this
|
|
92
92
|
*/
|
|
93
|
-
clone(instance: Model): this;
|
|
93
|
+
protected clone(instance: Model): this;
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
* Copy an instance of model
|
|
97
|
+
* @param {Model} instance instance of model
|
|
98
|
+
* @param {Object} options keep data
|
|
99
|
+
* @return {Model} Model
|
|
100
|
+
*/
|
|
101
|
+
protected copyModel(instance: Model, options?: {
|
|
102
|
+
update?: boolean;
|
|
103
|
+
insert?: boolean;
|
|
104
|
+
delete?: boolean;
|
|
105
|
+
where?: boolean;
|
|
106
|
+
}): Model;
|
|
94
107
|
/**
|
|
95
108
|
* Assign ignore delete_at in model
|
|
96
109
|
* @param {boolean} condition
|
|
@@ -125,6 +138,13 @@ declare class Model extends AbstractModel {
|
|
|
125
138
|
* @return {this} this
|
|
126
139
|
*/
|
|
127
140
|
withExists(...nameRelations: Array<string>): this;
|
|
141
|
+
/**
|
|
142
|
+
*
|
|
143
|
+
* Use relations in registry of model return only exists result of relation query
|
|
144
|
+
* @param {...string} nameRelations if data exists return blank
|
|
145
|
+
* @return {this} this
|
|
146
|
+
*/
|
|
147
|
+
has(...nameRelations: Array<string>): this;
|
|
128
148
|
/**
|
|
129
149
|
*
|
|
130
150
|
* Use relation '${name}' registry of model return callback this query model
|
|
@@ -204,19 +224,19 @@ declare class Model extends AbstractModel {
|
|
|
204
224
|
*/
|
|
205
225
|
protected belongsToMany({ name, as, model, localKey, foreignKey, freezeTable }: Relation): this;
|
|
206
226
|
/**
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
protected
|
|
227
|
+
* Assign the relation in model Objects
|
|
228
|
+
* @param {object} relation registry relation in your model
|
|
229
|
+
* @type {object} relation
|
|
230
|
+
* @property {class} model
|
|
231
|
+
* @property {string?} name
|
|
232
|
+
* @property {string?} as
|
|
233
|
+
* @property {string?} localKey
|
|
234
|
+
* @property {string?} foreignKey
|
|
235
|
+
* @property {string?} freezeTable
|
|
236
|
+
* @param {function?} callback callback of query
|
|
237
|
+
* @return {this} this
|
|
238
|
+
*/
|
|
239
|
+
protected hasOneBuilder({ name, as, model, localKey, foreignKey, freezeTable }: RelationQuery, callback?: Function): this;
|
|
220
240
|
/**
|
|
221
241
|
* Assign the relation in model Objects
|
|
222
242
|
* @param {object} relation registry relation in your model
|
|
@@ -230,7 +250,7 @@ declare class Model extends AbstractModel {
|
|
|
230
250
|
* @param {function?} callback callback of query
|
|
231
251
|
* @return {this} this
|
|
232
252
|
*/
|
|
233
|
-
protected
|
|
253
|
+
protected hasManyBuilder({ name, as, model, localKey, foreignKey, freezeTable }: RelationQuery, callback?: Function): this;
|
|
234
254
|
/**
|
|
235
255
|
* Assign the relation in model Objects
|
|
236
256
|
* @param {object} relation registry relation in your model
|
|
@@ -244,7 +264,7 @@ declare class Model extends AbstractModel {
|
|
|
244
264
|
* @param {function?} callback callback of query
|
|
245
265
|
* @return {this} this
|
|
246
266
|
*/
|
|
247
|
-
protected
|
|
267
|
+
protected belongsToBuilder({ name, as, model, localKey, foreignKey, freezeTable }: RelationQuery, callback?: Function): this;
|
|
248
268
|
/**
|
|
249
269
|
* Assign the relation in model Objects
|
|
250
270
|
* @param {object} relation registry relation in your model
|
|
@@ -258,7 +278,7 @@ declare class Model extends AbstractModel {
|
|
|
258
278
|
* @param {function?} callback callback of query
|
|
259
279
|
* @return {this} this
|
|
260
280
|
*/
|
|
261
|
-
protected
|
|
281
|
+
protected belongsToManyBuilder({ name, as, model, localKey, foreignKey, freezeTable }: RelationQuery, callback?: Function): this;
|
|
262
282
|
/**
|
|
263
283
|
* return only in trashed (data has been remove)
|
|
264
284
|
* @return {promise}
|
|
@@ -340,12 +360,24 @@ declare class Model extends AbstractModel {
|
|
|
340
360
|
* @return {promise<number>}
|
|
341
361
|
*/
|
|
342
362
|
count(column?: string): Promise<number>;
|
|
363
|
+
/**
|
|
364
|
+
*
|
|
365
|
+
* execute data return result is exists
|
|
366
|
+
* @return {promise<boolean>}
|
|
367
|
+
*/
|
|
368
|
+
exists(): Promise<boolean>;
|
|
343
369
|
/**
|
|
344
370
|
* delete data from the database
|
|
345
371
|
* @override Method
|
|
346
372
|
* @return {promise<boolean>}
|
|
347
373
|
*/
|
|
348
374
|
delete(): Promise<boolean>;
|
|
375
|
+
/**
|
|
376
|
+
*
|
|
377
|
+
* force delete data from the database
|
|
378
|
+
* @return {promise<boolean>}
|
|
379
|
+
*/
|
|
380
|
+
forceDelete(): Promise<boolean>;
|
|
349
381
|
/**
|
|
350
382
|
*
|
|
351
383
|
* @override Method
|
|
@@ -501,18 +533,37 @@ declare class Model extends AbstractModel {
|
|
|
501
533
|
* @return {this} this this
|
|
502
534
|
*/
|
|
503
535
|
insertMultiple(data: Array<Object>): this;
|
|
536
|
+
/**
|
|
537
|
+
*
|
|
538
|
+
* @param {object} data create not exists data
|
|
539
|
+
* @override Method
|
|
540
|
+
* @return {this} this this
|
|
541
|
+
*/
|
|
542
|
+
createNotExists(data: object): this;
|
|
504
543
|
/**
|
|
505
544
|
*
|
|
506
545
|
* @override Method
|
|
507
546
|
* @return {Promise<any>}
|
|
508
547
|
*/
|
|
509
|
-
save(): Promise<
|
|
548
|
+
save(): Promise<{
|
|
549
|
+
[key: string]: any;
|
|
550
|
+
} | Array<any> | null | undefined>;
|
|
551
|
+
/**
|
|
552
|
+
*
|
|
553
|
+
* fake data
|
|
554
|
+
* @param {number} rows number of rows
|
|
555
|
+
* @return {promise<any>}
|
|
556
|
+
*/
|
|
557
|
+
faker(rows?: number): Promise<{
|
|
558
|
+
[key: string]: any;
|
|
559
|
+
}[]>;
|
|
510
560
|
private _valuePattern;
|
|
511
561
|
private _isPatternSnakeCase;
|
|
512
562
|
private _classToTableName;
|
|
513
563
|
private _makeTableName;
|
|
514
564
|
private _tableName;
|
|
515
565
|
private _valueInRelation;
|
|
566
|
+
private _handleSoftDelete;
|
|
516
567
|
private _buildQueryModel;
|
|
517
568
|
private _showOnly;
|
|
518
569
|
private _execute;
|
|
@@ -541,9 +592,8 @@ declare class Model extends AbstractModel {
|
|
|
541
592
|
private _assertError;
|
|
542
593
|
private _functionRelationName;
|
|
543
594
|
private _handleRelationsQuery;
|
|
595
|
+
private _validateMethod;
|
|
544
596
|
private _initialModel;
|
|
545
|
-
private _setupModel;
|
|
546
|
-
private _bindMethod;
|
|
547
597
|
}
|
|
548
598
|
export { Model };
|
|
549
599
|
export default Model;
|