tspace-mysql 1.4.7 → 1.4.9
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 +128 -49
- package/dist/lib/{tspace/Interface.d.ts → Interface.d.ts} +18 -2
- package/dist/lib/connection/index.d.ts +1 -1
- package/dist/lib/constants/index.js +3 -3
- package/dist/lib/tspace/{Abstract → Abstracts}/AbstractBuilder.d.ts +3 -3
- package/dist/lib/tspace/{Abstract → Abstracts}/AbstractBuilder.js +2 -2
- package/dist/lib/tspace/{Abstract → Abstracts}/AbstractDB.d.ts +8 -2
- package/dist/lib/tspace/{Abstract → Abstracts}/AbstractModel.d.ts +22 -2
- package/dist/lib/tspace/Blueprint.d.ts +19 -5
- package/dist/lib/tspace/Blueprint.js +41 -19
- package/dist/lib/tspace/Builder.d.ts +26 -11
- package/dist/lib/tspace/Builder.js +378 -330
- package/dist/lib/tspace/DB.d.ts +42 -2
- package/dist/lib/tspace/DB.js +61 -5
- package/dist/lib/tspace/Decorator.d.ts +20 -0
- package/dist/lib/tspace/Decorator.js +166 -0
- package/dist/lib/tspace/{ProxyHandler.js → Handlers/Proxy.js} +1 -1
- package/dist/lib/tspace/{RelationHandler.d.ts → Handlers/Relation.d.ts} +4 -4
- package/dist/lib/tspace/{RelationHandler.js → Handlers/Relation.js} +103 -28
- package/dist/lib/tspace/{StateHandler.js → Handlers/State.js} +3 -2
- package/dist/lib/tspace/Model.d.ts +275 -11
- package/dist/lib/tspace/Model.js +989 -99
- package/dist/lib/tspace/Schema.js +5 -8
- package/dist/lib/tspace/index.d.ts +4 -0
- package/dist/lib/tspace/index.js +20 -2
- package/dist/lib/utils/index.d.ts +1 -0
- package/dist/lib/utils/index.js +9 -0
- package/dist/tests/01-Pool.test.d.ts +1 -0
- package/dist/tests/01-Pool.test.js +45 -0
- package/dist/tests/02-DB.test.d.ts +1 -0
- package/dist/tests/02-DB.test.js +109 -0
- package/dist/tests/03-Model.test.d.ts +1 -0
- package/dist/tests/03-Model.test.js +73 -0
- package/package.json +14 -3
- /package/dist/lib/{tspace/Interface.js → Interface.js} +0 -0
- /package/dist/lib/tspace/{Abstract → Abstracts}/AbstractDB.js +0 -0
- /package/dist/lib/tspace/{Abstract → Abstracts}/AbstractModel.js +0 -0
- /package/dist/lib/tspace/{ProxyHandler.d.ts → Handlers/Proxy.d.ts} +0 -0
- /package/dist/lib/tspace/{StateHandler.d.ts → Handlers/State.d.ts} +0 -0
|
@@ -5,7 +5,7 @@ exports.Blueprint = void 0;
|
|
|
5
5
|
* Make schema for table with Blueprint
|
|
6
6
|
* @example
|
|
7
7
|
* import { Schema , Blueprint } from 'tspace-mysql'
|
|
8
|
-
* await new Schema().table('
|
|
8
|
+
* await new Schema().table('users',{
|
|
9
9
|
* id : new Blueprint().int().notNull().primary().autoIncrement(),
|
|
10
10
|
* name : new Blueprint().varchar(255).default('my name'),
|
|
11
11
|
* email : new Blueprint().varchar(255).unique(),
|
|
@@ -18,10 +18,10 @@ exports.Blueprint = void 0;
|
|
|
18
18
|
*/
|
|
19
19
|
class Blueprint {
|
|
20
20
|
constructor() {
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
21
|
+
this._type = 'INT';
|
|
22
|
+
this._attributes = [];
|
|
23
|
+
this._foreignKey = null;
|
|
24
|
+
this._valueType = String;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Assign type 'int' in table
|
|
@@ -29,7 +29,7 @@ class Blueprint {
|
|
|
29
29
|
*/
|
|
30
30
|
int(_) {
|
|
31
31
|
this._addAssignType('INT');
|
|
32
|
-
this.
|
|
32
|
+
this._valueType = Number;
|
|
33
33
|
return this;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
@@ -39,7 +39,7 @@ class Blueprint {
|
|
|
39
39
|
*/
|
|
40
40
|
tinyInt(number = 1) {
|
|
41
41
|
this._addAssignType(`TINYINT(${number})`);
|
|
42
|
-
this.
|
|
42
|
+
this._valueType = Number;
|
|
43
43
|
return this;
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
@@ -49,7 +49,7 @@ class Blueprint {
|
|
|
49
49
|
*/
|
|
50
50
|
tinyint(number = 1) {
|
|
51
51
|
this._addAssignType(`TINYINT(${number})`);
|
|
52
|
-
this.
|
|
52
|
+
this._valueType = Number;
|
|
53
53
|
return this;
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
@@ -59,7 +59,7 @@ class Blueprint {
|
|
|
59
59
|
*/
|
|
60
60
|
bigInt(number = 10) {
|
|
61
61
|
this._addAssignType(`BIGINT(${number})`);
|
|
62
|
-
this.
|
|
62
|
+
this._valueType = Number;
|
|
63
63
|
return this;
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
@@ -69,7 +69,7 @@ class Blueprint {
|
|
|
69
69
|
*/
|
|
70
70
|
bigint(number = 10) {
|
|
71
71
|
this._addAssignType(`BIGINT(${number})`);
|
|
72
|
-
this.
|
|
72
|
+
this._valueType = Number;
|
|
73
73
|
return this;
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
@@ -79,7 +79,7 @@ class Blueprint {
|
|
|
79
79
|
* @return {this} this
|
|
80
80
|
*/
|
|
81
81
|
double(length = 0, decimal = 0) {
|
|
82
|
-
this.
|
|
82
|
+
this._valueType = Number;
|
|
83
83
|
if (!length || !decimal) {
|
|
84
84
|
this._addAssignType(`DOUBLE`);
|
|
85
85
|
return this;
|
|
@@ -94,7 +94,7 @@ class Blueprint {
|
|
|
94
94
|
* @return {this} this
|
|
95
95
|
*/
|
|
96
96
|
float(length = 0, decimal = 0) {
|
|
97
|
-
this.
|
|
97
|
+
this._valueType = Number;
|
|
98
98
|
if (!length || !decimal) {
|
|
99
99
|
this._addAssignType(`FLOAT`);
|
|
100
100
|
return this;
|
|
@@ -204,7 +204,7 @@ class Blueprint {
|
|
|
204
204
|
*/
|
|
205
205
|
date() {
|
|
206
206
|
this._addAssignType(`DATE`);
|
|
207
|
-
this.
|
|
207
|
+
this._valueType = Date;
|
|
208
208
|
return this;
|
|
209
209
|
}
|
|
210
210
|
/**
|
|
@@ -213,7 +213,7 @@ class Blueprint {
|
|
|
213
213
|
*/
|
|
214
214
|
dateTime() {
|
|
215
215
|
this._addAssignType(`DATETIME`);
|
|
216
|
-
this.
|
|
216
|
+
this._valueType = Date;
|
|
217
217
|
return this;
|
|
218
218
|
}
|
|
219
219
|
/**
|
|
@@ -222,7 +222,7 @@ class Blueprint {
|
|
|
222
222
|
*/
|
|
223
223
|
datetime() {
|
|
224
224
|
this._addAssignType(`DATETIME`);
|
|
225
|
-
this.
|
|
225
|
+
this._valueType = Date;
|
|
226
226
|
return this;
|
|
227
227
|
}
|
|
228
228
|
/**
|
|
@@ -231,7 +231,7 @@ class Blueprint {
|
|
|
231
231
|
*/
|
|
232
232
|
timestamp() {
|
|
233
233
|
this._addAssignType(`TIMESTAMP`);
|
|
234
|
-
this.
|
|
234
|
+
this._valueType = Date;
|
|
235
235
|
return this;
|
|
236
236
|
}
|
|
237
237
|
/**
|
|
@@ -315,8 +315,18 @@ class Blueprint {
|
|
|
315
315
|
this._addAssignAttribute(`AUTO_INCREMENT`);
|
|
316
316
|
return this;
|
|
317
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Assign attributes 'foreign' in table
|
|
320
|
+
* Reference bettwen Column Main to Column Child
|
|
321
|
+
* @param {object} property object { key , value , operator }
|
|
322
|
+
* @property {string?} property.reference
|
|
323
|
+
* @property {Model | string} property.on
|
|
324
|
+
* @property {string?} property.onDelete
|
|
325
|
+
* @property {string?} property.onUpdate
|
|
326
|
+
* @return {this} this
|
|
327
|
+
*/
|
|
318
328
|
foreign({ references, on, onDelete, onUpdate }) {
|
|
319
|
-
this.
|
|
329
|
+
this._foreignKey = {
|
|
320
330
|
references: references == null ? 'id' : references,
|
|
321
331
|
on: typeof on === 'string' ? on : new on(),
|
|
322
332
|
onDelete: onDelete == null ? 'CASCADE' : onDelete,
|
|
@@ -324,12 +334,24 @@ class Blueprint {
|
|
|
324
334
|
};
|
|
325
335
|
return this;
|
|
326
336
|
}
|
|
337
|
+
get type() {
|
|
338
|
+
return this._type;
|
|
339
|
+
}
|
|
340
|
+
get attributes() {
|
|
341
|
+
return this._attributes;
|
|
342
|
+
}
|
|
343
|
+
get foreignKey() {
|
|
344
|
+
return this._foreignKey;
|
|
345
|
+
}
|
|
346
|
+
get valueType() {
|
|
347
|
+
return this._valueType;
|
|
348
|
+
}
|
|
327
349
|
_addAssignType(type) {
|
|
328
|
-
this.
|
|
350
|
+
this._type = type;
|
|
329
351
|
return this;
|
|
330
352
|
}
|
|
331
353
|
_addAssignAttribute(attribute) {
|
|
332
|
-
this.
|
|
354
|
+
this._attributes = [...this.attributes, attribute];
|
|
333
355
|
return this;
|
|
334
356
|
}
|
|
335
357
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractBuilder } from './
|
|
2
|
-
import { Pagination, Backup, ConnectionOptions, BackupToFile, Connection, ConnectionTransaction, BackupTableToFile } from '
|
|
1
|
+
import { AbstractBuilder } from './Abstracts/AbstractBuilder';
|
|
2
|
+
import { Pagination, Backup, ConnectionOptions, BackupToFile, Connection, ConnectionTransaction, BackupTableToFile } from '../Interface';
|
|
3
3
|
declare class Builder extends AbstractBuilder {
|
|
4
4
|
constructor();
|
|
5
5
|
/**
|
|
@@ -94,7 +94,7 @@ declare class Builder extends AbstractBuilder {
|
|
|
94
94
|
* @param {any?} value
|
|
95
95
|
* @return {this}
|
|
96
96
|
*/
|
|
97
|
-
where(column: string |
|
|
97
|
+
where(column: string | Record<string, any>, operator?: any, value?: any): this;
|
|
98
98
|
/**
|
|
99
99
|
* The 'orWhere' method is used to add conditions to a database query.
|
|
100
100
|
*
|
|
@@ -403,6 +403,14 @@ declare class Builder extends AbstractBuilder {
|
|
|
403
403
|
* @return {this}
|
|
404
404
|
*/
|
|
405
405
|
orWhereQuery(callback: Function): this;
|
|
406
|
+
/**
|
|
407
|
+
* The 'orWhereGroup' method is used to add conditions to a database query to create a grouped condition.
|
|
408
|
+
*
|
|
409
|
+
* It allows you to specify conditions that records in the database must meet in order to be included in the result set.
|
|
410
|
+
* @param {function} callback callback query
|
|
411
|
+
* @return {this}
|
|
412
|
+
*/
|
|
413
|
+
orWhereGroup(callback: Function): this;
|
|
406
414
|
/**
|
|
407
415
|
* The 'whereCases' method is used to add conditions with cases to a database query.
|
|
408
416
|
*
|
|
@@ -829,12 +837,18 @@ declare class Builder extends AbstractBuilder {
|
|
|
829
837
|
*/
|
|
830
838
|
toRawSQL(): string;
|
|
831
839
|
/**
|
|
832
|
-
*
|
|
840
|
+
* The 'getTableName' method is used to get table name
|
|
833
841
|
* @return {string} return table name
|
|
834
842
|
*/
|
|
835
843
|
getTableName(): string;
|
|
836
844
|
/**
|
|
837
|
-
*
|
|
845
|
+
* The 'getSchema' method is used to get schema information
|
|
846
|
+
* @return {this} this this
|
|
847
|
+
*/
|
|
848
|
+
getSchema(): Promise<any[]>;
|
|
849
|
+
/**
|
|
850
|
+
* The 'bindColumn' method is used to concat table and column -> `users`.`id`
|
|
851
|
+
* @param {string} column
|
|
838
852
|
* @return {string} return table.column
|
|
839
853
|
*/
|
|
840
854
|
bindColumn(column: string): string;
|
|
@@ -1251,7 +1265,7 @@ declare class Builder extends AbstractBuilder {
|
|
|
1251
1265
|
* @param {number} rows number of rows
|
|
1252
1266
|
* @return {promise<any>}
|
|
1253
1267
|
*/
|
|
1254
|
-
faker(rows?:
|
|
1268
|
+
faker(rows: number, cb?: Function): Promise<Record<string, any>[]>;
|
|
1255
1269
|
/**
|
|
1256
1270
|
*
|
|
1257
1271
|
* truncate of table
|
|
@@ -1264,7 +1278,7 @@ declare class Builder extends AbstractBuilder {
|
|
|
1264
1278
|
* @return {promise<boolean>}
|
|
1265
1279
|
*/
|
|
1266
1280
|
drop(): Promise<boolean>;
|
|
1267
|
-
protected
|
|
1281
|
+
protected exceptColumns(): Promise<string[]>;
|
|
1268
1282
|
protected _updateHandler(column: string, value?: string | number | null | boolean): string;
|
|
1269
1283
|
protected copyBuilder(instance: Builder, options?: {
|
|
1270
1284
|
update?: boolean;
|
|
@@ -1282,6 +1296,7 @@ declare class Builder extends AbstractBuilder {
|
|
|
1282
1296
|
insert: () => string;
|
|
1283
1297
|
update: () => string;
|
|
1284
1298
|
delete: () => string;
|
|
1299
|
+
where: () => string | null;
|
|
1285
1300
|
any: () => string;
|
|
1286
1301
|
};
|
|
1287
1302
|
protected _buildQueryStatement(): {
|
|
@@ -1289,6 +1304,7 @@ declare class Builder extends AbstractBuilder {
|
|
|
1289
1304
|
insert: () => string;
|
|
1290
1305
|
update: () => string;
|
|
1291
1306
|
delete: () => string;
|
|
1307
|
+
where: () => string | null;
|
|
1292
1308
|
any: () => string;
|
|
1293
1309
|
};
|
|
1294
1310
|
protected _getState(key: string): any;
|
|
@@ -1300,10 +1316,9 @@ declare class Builder extends AbstractBuilder {
|
|
|
1300
1316
|
sql: string;
|
|
1301
1317
|
returnId?: boolean;
|
|
1302
1318
|
}): Promise<any>;
|
|
1303
|
-
private _queryWhereIsExists;
|
|
1304
1319
|
private _insertNotExists;
|
|
1305
1320
|
private _insert;
|
|
1306
|
-
|
|
1321
|
+
protected _checkValueHasRaw(value: any): string;
|
|
1307
1322
|
private _insertMultiple;
|
|
1308
1323
|
private _insertOrSelect;
|
|
1309
1324
|
private _updateOrInsert;
|
|
@@ -1312,8 +1327,8 @@ declare class Builder extends AbstractBuilder {
|
|
|
1312
1327
|
private _queryUpdate;
|
|
1313
1328
|
private _queryInsert;
|
|
1314
1329
|
private _queryInsertMultiple;
|
|
1315
|
-
|
|
1316
|
-
|
|
1330
|
+
protected _valueAndOperator(value: string, operator: string, useDefault?: boolean): string[];
|
|
1331
|
+
protected _valueTrueFalse(value: any): any;
|
|
1317
1332
|
private _initialConnection;
|
|
1318
1333
|
}
|
|
1319
1334
|
export { Builder };
|