tspace-mysql 1.6.5-dev.1 → 1.6.6-dev.1
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 +50 -3
- package/build/cli/models/make.js +2 -2
- package/build/cli/models/make.js.map +1 -1
- package/build/cli/models/model.d.ts +5 -1
- package/build/cli/models/model.js +31 -2
- package/build/cli/models/model.js.map +1 -1
- package/build/cli/tables/make.js +1 -1
- package/build/cli/tables/make.js.map +1 -1
- package/build/cli/tables/table.d.ts +5 -1
- package/build/cli/tables/table.js +32 -4
- package/build/cli/tables/table.js.map +1 -1
- package/build/lib/core/Builder.d.ts +16 -0
- package/build/lib/core/Builder.js +44 -9
- package/build/lib/core/Builder.js.map +1 -1
- package/build/lib/core/Handlers/State.js +1 -9
- package/build/lib/core/Handlers/State.js.map +1 -1
- package/build/lib/core/Model.js +2 -2
- package/build/lib/core/Model.js.map +1 -1
- package/build/tests/01-Pool.test.js +2 -2
- package/build/tests/01-Pool.test.js.map +1 -1
- package/build/tests/02-DB.test.js.map +1 -1
- package/build/tests/03-Model.test.js +2 -2
- package/build/tests/03-Model.test.js.map +1 -1
- package/build/tests/schema-spec.d.ts +72 -24
- package/build/tests/schema-spec.js +6 -6
- package/build/tests/schema-spec.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -47,6 +47,7 @@ npm install tspace-mysql -g
|
|
|
47
47
|
- [Delete Statements](#delete-statements)
|
|
48
48
|
- [Hook Statements](#hook-statements)
|
|
49
49
|
- [Faker Statements](#faker-statements)
|
|
50
|
+
- [Unset Statements](#unset-statements)
|
|
50
51
|
- [More Methods](#more-methods)
|
|
51
52
|
- [Database Transactions](#database-transactions)
|
|
52
53
|
- [Connection](#connection)
|
|
@@ -122,7 +123,7 @@ DB_DATABASE = database;
|
|
|
122
123
|
* DB_CONNECTION_LIMIT = 10
|
|
123
124
|
* DB_QUEUE_LIMIT = 0
|
|
124
125
|
* DB_TIMEOUT = 60000
|
|
125
|
-
* DB_DATE_STRINGS =
|
|
126
|
+
* DB_DATE_STRINGS = false
|
|
126
127
|
*/
|
|
127
128
|
```
|
|
128
129
|
|
|
@@ -254,8 +255,31 @@ const selectObject = await new DB("posts")
|
|
|
254
255
|
)
|
|
255
256
|
.findOne();
|
|
256
257
|
|
|
257
|
-
|
|
258
|
-
|
|
258
|
+
/**
|
|
259
|
+
SELECT
|
|
260
|
+
posts.*, JSON_OBJECT('id' , `users`.`id` , 'name' , `users`.`name` , 'email' , `users`.`email`) AS `user`
|
|
261
|
+
FROM `posts`
|
|
262
|
+
INNER JOIN `users` ON `posts`.`user_id` = `users`.`id` LIMIT 1;
|
|
263
|
+
*/
|
|
264
|
+
|
|
265
|
+
const selectArray = await new DB("users")
|
|
266
|
+
.select('id','name','email')
|
|
267
|
+
.join("users.id", "posts.user_id")
|
|
268
|
+
.select("posts.*")
|
|
269
|
+
.selectArray(
|
|
270
|
+
{ id: "posts.id", user_id: "posts.user_id", title: "posts.title" },
|
|
271
|
+
"posts"
|
|
272
|
+
)
|
|
273
|
+
.findOne();
|
|
274
|
+
/**
|
|
275
|
+
SELECT
|
|
276
|
+
`users`.`id`, `users`.`name`, `users`.`email`,
|
|
277
|
+
CASE WHEN COUNT(`posts`.`id`) = 0 THEN JSON_ARRAY()
|
|
278
|
+
ELSE JSON_ARRAYAGG(JSON_OBJECT('id' , `posts`.`id` , 'user_id' , `posts`.`user_id` , 'email' , `posts`.`title`))
|
|
279
|
+
END AS `posts`
|
|
280
|
+
FROM `users`
|
|
281
|
+
INNER JOIN `posts` ON `users`.`id` = `posts`.`user_id` WHERE `users`.`deletedAt` IS NULL GROUP BY `users`.`id` LIMIT 1;
|
|
282
|
+
*/
|
|
259
283
|
|
|
260
284
|
await new DB("users").except("id").findOne();
|
|
261
285
|
// SELECT `users`.`email`, `users`.`username` FROM `users` LIMIT 1;
|
|
@@ -850,6 +874,29 @@ VALUES
|
|
|
850
874
|
('username-5','email-5');
|
|
851
875
|
|
|
852
876
|
*/
|
|
877
|
+
|
|
878
|
+
// fast to create
|
|
879
|
+
await new DB("users").faker(40_000);
|
|
880
|
+
```
|
|
881
|
+
|
|
882
|
+
## Unset Statements
|
|
883
|
+
|
|
884
|
+
```js
|
|
885
|
+
|
|
886
|
+
const userInstance = new User().where('email','test@gmail.com')
|
|
887
|
+
|
|
888
|
+
const exits = await userInstance.exists()
|
|
889
|
+
// SELECT EXISTS (SELECT 1 FROM `users` WHERE `users`.`email` = 'test@gmail.com' LIMIT 1) AS `aggregate`;
|
|
890
|
+
|
|
891
|
+
const user = await userInstance.orderBy('id').findOne()
|
|
892
|
+
// SELECT * FROM `users` WHERE `users`.`email` = 'test@gmail.com' ORDER BY `users`.`id` DESC LIMIT 1;
|
|
893
|
+
|
|
894
|
+
const users = await userInstance.select('id').unset({ limit : true }).findMany()
|
|
895
|
+
// SELECT `users`.`id` FROM `users` WHERE `users`.`email` = 'test@gmail.com' ORDER BY `users`.`id` DESC;
|
|
896
|
+
|
|
897
|
+
const usersUnsetWhereStatement = await userInstance.unset({ select : true, where : true , orderBy : true }).findMany()
|
|
898
|
+
// SELECT * FROM `users` WHERE `users`.`deletedAt` IS NULL;
|
|
899
|
+
|
|
853
900
|
```
|
|
854
901
|
|
|
855
902
|
## More Methods
|
package/build/cli/models/make.js
CHANGED
|
@@ -21,7 +21,7 @@ exports.default = (cmd) => {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
const model = dir ? `${cwd}/${dir}/${file}${type}` : `${cwd}/${file}${type}`;
|
|
24
|
-
const data = (0, model_1.default)(file, npm);
|
|
24
|
+
const data = (0, model_1.default)({ model: file, npm, type });
|
|
25
25
|
fs.writeFile(model, data, (err) => {
|
|
26
26
|
if (err)
|
|
27
27
|
throw err.message;
|
|
@@ -41,7 +41,7 @@ exports.default = (cmd) => {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
const folderMigrate = `${cwd}/${folder}/create_${tableName}_table${type}`;
|
|
44
|
-
const table = (0, table_1.default)(tableName, npm);
|
|
44
|
+
const table = (0, table_1.default)({ table: tableName, npm, type });
|
|
45
45
|
fs.writeFile(folderMigrate, table, (err) => {
|
|
46
46
|
if (err)
|
|
47
47
|
throw err;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make.js","sourceRoot":"","sources":["../../../src/cli/models/make.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAC5B,4DAAmC;AACnC,0DAAiC;AAEjC,kBAAe,CAAC,GAA0B,EAAE,EAAE;IAC5C,MAAM,EACJ,IAAI,EACJ,OAAO,EACP,GAAG,EACH,IAAI,EACJ,GAAG,EACH,EAAE,EACF,GAAG,EACJ,GAAG,GAAG,CAAA;IAEP,IAAG,GAAG,EAAE,CAAC;QACP,IAAI,CAAC;YACD,EAAE,CAAC,UAAU,CAAC,GAAG,GAAG,IAAI,GAAG,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE;gBACpC,SAAS,EAAE,IAAI;aAClB,CAAC,CAAA;QACN,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,EAAE,CAAC,SAAS,CAAC,GAAG,GAAG,IAAI,GAAG,EAAE,EAAE;gBAC1B,SAAS,EAAE,IAAI;aAClB,CAAC,CAAA;QACN,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,CAAE,GAAG,GAAG,IAAI,GAAG,IAAI,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,IAAI,GAAG,IAAI,EAAE,CAAA;IAC7E,MAAM,IAAI,GAAG,IAAA,eAAK,EAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"make.js","sourceRoot":"","sources":["../../../src/cli/models/make.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAC5B,4DAAmC;AACnC,0DAAiC;AAEjC,kBAAe,CAAC,GAA0B,EAAE,EAAE;IAC5C,MAAM,EACJ,IAAI,EACJ,OAAO,EACP,GAAG,EACH,IAAI,EACJ,GAAG,EACH,EAAE,EACF,GAAG,EACJ,GAAG,GAAG,CAAA;IAEP,IAAG,GAAG,EAAE,CAAC;QACP,IAAI,CAAC;YACD,EAAE,CAAC,UAAU,CAAC,GAAG,GAAG,IAAI,GAAG,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE;gBACpC,SAAS,EAAE,IAAI;aAClB,CAAC,CAAA;QACN,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,EAAE,CAAC,SAAS,CAAC,GAAG,GAAG,IAAI,GAAG,EAAE,EAAE;gBAC1B,SAAS,EAAE,IAAI;aAClB,CAAC,CAAA;QACN,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,CAAE,GAAG,GAAG,IAAI,GAAG,IAAI,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,IAAI,GAAG,IAAI,EAAE,CAAA;IAC7E,MAAM,IAAI,GAAG,IAAA,eAAK,EAAC,EAAE,KAAK,EAAG,IAAI,EAAG,GAAG,EAAG,IAAI,EAAE,CAAC,CAAC;IAClD,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,GAAO,EAAE,EAAE;QACpC,IAAI,GAAG;YAAE,MAAM,GAAG,CAAC,OAAO,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,wBAAwB,CAAC,CAAC;IAEtD,IAAG,OAAO,EAAE,CAAC;QACX,MAAM,SAAS,GAAI,IAAA,mBAAS,EAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAE,GAAU,EAAG,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QAE1G,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,aAAa,CAAC,CAAC,CAAC,aAAa,CAAA;QAExD,IAAI,CAAC;YACH,EAAE,CAAC,UAAU,CAAC,GAAG,GAAG,MAAM,EAAE,EAAE,CAAC,IAAI,EAAE;gBACnC,SAAS,EAAE,IAAI;aAChB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,EAAE,CAAC,SAAS,CAAC,GAAG,GAAG,MAAM,EAAE;gBACzB,SAAS,EAAE,IAAI;aAChB,CAAC,CAAC;QACL,CAAC;QAED,MAAM,aAAa,GAAI,GAAG,GAAG,IAAI,MAAM,WAAW,SAAS,SAAS,IAAI,EAAE,CAAC;QAC3E,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,EAAE,KAAK,EAAG,SAAS,EAAG,GAAG,EAAG,IAAI,EAAE,CAAC,CAAC;QACxD,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,KAAK,EAAE,CAAC,GAAO,EAAE,EAAE;YAC7C,IAAI,GAAG;gBAAE,MAAM,GAAG,CAAC;QACrB,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,gBAAgB,SAAS,wBAAwB,CAAC,CAAA;IAChE,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -1,7 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const Model = (model, npm) => {
|
|
4
|
-
|
|
3
|
+
const Model = ({ model, npm, type }) => {
|
|
4
|
+
switch (type.replace(/./, '').toLocaleLowerCase()) {
|
|
5
|
+
case 'js': {
|
|
6
|
+
return `const { Model } = require('${npm}');
|
|
7
|
+
|
|
8
|
+
class ${model} extends Model {
|
|
9
|
+
constructor(){
|
|
10
|
+
super()
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* //Assign setting global in your model
|
|
14
|
+
* @useMethod
|
|
15
|
+
*
|
|
16
|
+
* this.useDebug()
|
|
17
|
+
* this.usePrimaryKey('id')
|
|
18
|
+
* this.useTimestamp({
|
|
19
|
+
* createdAt : 'created_at',
|
|
20
|
+
* updatedAt : 'updated_at'
|
|
21
|
+
* }) // runing a timestamp when insert or update
|
|
22
|
+
*/
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
module.exports = ${model};
|
|
26
|
+
module.exports = { ${model} };
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
case 'ts': {
|
|
30
|
+
return `import { Model } from '${npm}';
|
|
31
|
+
|
|
5
32
|
class ${model} extends Model {
|
|
6
33
|
constructor(){
|
|
7
34
|
super()
|
|
@@ -22,6 +49,8 @@ class ${model} extends Model {
|
|
|
22
49
|
export { ${model} }
|
|
23
50
|
export default ${model}
|
|
24
51
|
`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
25
54
|
};
|
|
26
55
|
exports.default = Model;
|
|
27
56
|
//# sourceMappingURL=model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../src/cli/models/model.ts"],"names":[],"mappings":";;AAAA,MAAM,KAAK,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../src/cli/models/model.ts"],"names":[],"mappings":";;AAAA,MAAM,KAAK,GAAG,CAAC,EAAE,KAAK,EAAG,GAAG,EAAG,IAAI,EAAmD,EAAE,EAAE;IAExF,QAAQ,IAAI,CAAC,OAAO,CAAC,GAAG,EAAC,EAAE,CAAC,CAAC,iBAAiB,EAAE,EAAE,CAAC;QAEjD,KAAK,IAAK,CAAC,CAAC,CAAC;YACjB,OAAO,8BAA8B,GAAG;;QAEhC,KAAK;;;;;;;;;;;;;;;;;mBAiBM,KAAK;qBACH,KAAK;CACzB,CAAA;QACG,CAAC;QAED,KAAK,IAAK,CAAC,CAAC,CAAC;YACjB,OAAO,0BAA0B,GAAG;;QAE5B,KAAK;;;;;;;;;;;;;;;;;WAiBF,KAAK;iBACC,KAAK;CACrB,CAAA;QACG,CAAC;IACH,CAAC;AACH,CAAC,CAAA;AAED,kBAAe,KAAK,CAAA"}
|
package/build/cli/tables/make.js
CHANGED
|
@@ -17,7 +17,7 @@ exports.default = (formCommand) => {
|
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
const folderMigrate = dir ? `${cwd}/${dir}/create_${file}_table${type}` : `${cwd}/create_${file}_table${type}`;
|
|
20
|
-
const table = (0, table_1.default)(file, npm);
|
|
20
|
+
const table = (0, table_1.default)({ table: file, npm, type });
|
|
21
21
|
fs.writeFile(folderMigrate, table, (err) => {
|
|
22
22
|
if (err)
|
|
23
23
|
console.log(err.message);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make.js","sourceRoot":"","sources":["../../../src/cli/tables/make.ts"],"names":[],"mappings":";;;;;AAAA,oDAA2B;AAC3B,kBAAe,CAAC,WAAiC,EAAE,EAAE;IACnD,MAAM,EACJ,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,GAAG,EACH,EAAE,EACF,GAAG,EACJ,GAAG,WAAW,CAAC;IAEhB,IAAI,CAAC;QACH,EAAE,CAAC,UAAU,CAAC,GAAG,GAAG,IAAI,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE;YACvC,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,EAAE,CAAC,SAAS,CAAC,GAAG,GAAG,IAAI,IAAI,EAAE,EAAE;YAC7B,SAAS,EAAE,IAAI;SAChB,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,aAAa,GAAG,GAAG,CAAC,CAAC,CAAE,GAAG,GAAG,IAAI,GAAG,WAAW,IAAI,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,WAAW,IAAI,SAAS,IAAI,EAAE,CAAA;IAC/G,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,IAAI,EAAG,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"make.js","sourceRoot":"","sources":["../../../src/cli/tables/make.ts"],"names":[],"mappings":";;;;;AAAA,oDAA2B;AAC3B,kBAAe,CAAC,WAAiC,EAAE,EAAE;IACnD,MAAM,EACJ,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,GAAG,EACH,EAAE,EACF,GAAG,EACJ,GAAG,WAAW,CAAC;IAEhB,IAAI,CAAC;QACH,EAAE,CAAC,UAAU,CAAC,GAAG,GAAG,IAAI,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE;YACvC,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,EAAE,CAAC,SAAS,CAAC,GAAG,GAAG,IAAI,IAAI,EAAE,EAAE;YAC7B,SAAS,EAAE,IAAI;SAChB,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,aAAa,GAAG,GAAG,CAAC,CAAC,CAAE,GAAG,GAAG,IAAI,GAAG,WAAW,IAAI,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,WAAW,IAAI,SAAS,IAAI,EAAE,CAAA;IAC/G,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,EAAE,KAAK,EAAG,IAAI,EAAG,GAAG,EAAG,IAAI,EAAC,CAAC,CAAC;IAClD,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,KAAK,EAAE,CAAC,GAAO,EAAE,EAAE;QAC7C,IAAI,GAAG;YAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,uBAAuB,CAAC,CAAC;AAC1D,CAAC,CAAC"}
|
|
@@ -1,7 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const Table = (table, npm) => {
|
|
4
|
-
|
|
3
|
+
const Table = ({ table, npm, type }) => {
|
|
4
|
+
switch (type.replace(/./, '').toLocaleLowerCase()) {
|
|
5
|
+
case 'js': {
|
|
6
|
+
return `const { Schema , Blueprint , DB } = require('${npm}');
|
|
7
|
+
|
|
8
|
+
(async () => {
|
|
9
|
+
await new Schema().table('${table}', {
|
|
10
|
+
id : new Blueprint().int().notNull().primary().autoIncrement(),
|
|
11
|
+
uuid : new Blueprint().varchar(50).null(),
|
|
12
|
+
name : new Blueprint().varchar(120).default('my name'),
|
|
13
|
+
email : new Blueprint().varchar(120).unique(),
|
|
14
|
+
email_verify : new Blueprint().tinyInt(),
|
|
15
|
+
password : new Blueprint().varchar(120),
|
|
16
|
+
birthdate : new Blueprint().date(),
|
|
17
|
+
created_at : new Blueprint().timestamp().null(),
|
|
18
|
+
updated_at : new Blueprint().timestamp().null()
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @Faker data
|
|
24
|
+
* await new DB().table('${table}').faker(5)
|
|
25
|
+
*/
|
|
26
|
+
})()
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
case 'ts': {
|
|
30
|
+
return `import { Schema , Blueprint , DB } from '${npm}';
|
|
5
31
|
(async () => {
|
|
6
32
|
await new Schema().table('${table}',{
|
|
7
33
|
id : new Blueprint().int().notNull().primary().autoIncrement(),
|
|
@@ -11,8 +37,8 @@ const Table = (table, npm) => {
|
|
|
11
37
|
email_verify : new Blueprint().tinyInt(),
|
|
12
38
|
password : new Blueprint().varchar(120),
|
|
13
39
|
birthdate : new Blueprint().date(),
|
|
14
|
-
created_at : new Blueprint().
|
|
15
|
-
updated_at : new Blueprint().
|
|
40
|
+
created_at : new Blueprint().timestamp().null(),
|
|
41
|
+
updated_at : new Blueprint().timestamp().null()
|
|
16
42
|
})
|
|
17
43
|
|
|
18
44
|
/**
|
|
@@ -22,6 +48,8 @@ const Table = (table, npm) => {
|
|
|
22
48
|
*/
|
|
23
49
|
})()
|
|
24
50
|
`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
25
53
|
};
|
|
26
54
|
exports.default = Table;
|
|
27
55
|
//# sourceMappingURL=table.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../../src/cli/tables/table.ts"],"names":[],"mappings":";;AAAA,MAAM,KAAK,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../../src/cli/tables/table.ts"],"names":[],"mappings":";;AAAA,MAAM,KAAK,GAAG,CAAC,EAAC,KAAK,EAAG,GAAG,EAAG,IAAI,EAAkD,EAAE,EAAE;IAEpF,QAAQ,IAAI,CAAC,OAAO,CAAC,GAAG,EAAC,EAAE,CAAC,CAAC,iBAAiB,EAAE,EAAE,CAAC;QAC/C,KAAK,IAAK,CAAC,CAAC,CAAC;YACrB,OAAO,gDAAgD,GAAG;;;gCAG1B,KAAK;;;;;;;;;;;;;;;gCAeL,KAAK;;;CAGpC,CAAA;QACO,CAAC;QAED,KAAK,IAAK,CAAC,CAAC,CAAC;YACrB,OAAO,4CAA4C,GAAG;;gCAEtB,KAAK;;;;;;;;;;;;;;;gCAeL,KAAK;;;CAGpC,CAAA;QACO,CAAC;IACL,CAAC;AACL,CAAC,CAAA;AACD,kBAAe,KAAK,CAAA"}
|
|
@@ -8,6 +8,21 @@ declare class Builder extends AbstractBuilder {
|
|
|
8
8
|
* @returns {Builder} instance of the Builder
|
|
9
9
|
*/
|
|
10
10
|
static get instance(): Builder;
|
|
11
|
+
/**
|
|
12
|
+
* The 'unset' method is used to drop a property as desired.
|
|
13
|
+
*
|
|
14
|
+
* @returns {this} this
|
|
15
|
+
*/
|
|
16
|
+
unset(options: {
|
|
17
|
+
select?: boolean;
|
|
18
|
+
where?: boolean;
|
|
19
|
+
join?: boolean;
|
|
20
|
+
limit?: boolean;
|
|
21
|
+
offset?: boolean;
|
|
22
|
+
orderBy?: boolean;
|
|
23
|
+
groupBy?: boolean;
|
|
24
|
+
having?: boolean;
|
|
25
|
+
}): this;
|
|
11
26
|
/**
|
|
12
27
|
* The 'distinct' method is used to apply the DISTINCT keyword to a database query.
|
|
13
28
|
*
|
|
@@ -1386,6 +1401,7 @@ declare class Builder extends AbstractBuilder {
|
|
|
1386
1401
|
any: () => string;
|
|
1387
1402
|
};
|
|
1388
1403
|
protected _resultHandler(data: any): any;
|
|
1404
|
+
protected _resultHandlerExists(data: any): any;
|
|
1389
1405
|
whereReference(tableAndLocalKey: string, tableAndForeignKey?: string): this;
|
|
1390
1406
|
protected _queryStatement(sql: string): Promise<any[]>;
|
|
1391
1407
|
protected _actionStatement({ sql, returnId }: {
|
|
@@ -40,6 +40,30 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
40
40
|
static get instance() {
|
|
41
41
|
return new this();
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The 'unset' method is used to drop a property as desired.
|
|
45
|
+
*
|
|
46
|
+
* @returns {this} this
|
|
47
|
+
*/
|
|
48
|
+
unset(options) {
|
|
49
|
+
if ((options === null || options === void 0 ? void 0 : options.select) != null && options.select)
|
|
50
|
+
this.$state.set('SELECT', []);
|
|
51
|
+
if ((options === null || options === void 0 ? void 0 : options.join) != null && options.join)
|
|
52
|
+
this.$state.set('JOIN', []);
|
|
53
|
+
if ((options === null || options === void 0 ? void 0 : options.where) != null && options.where)
|
|
54
|
+
this.$state.set('WHERE', []);
|
|
55
|
+
if ((options === null || options === void 0 ? void 0 : options.groupBy) != null && options.groupBy)
|
|
56
|
+
this.$state.set('GROUP_BY', []);
|
|
57
|
+
if ((options === null || options === void 0 ? void 0 : options.having) != null && options.having)
|
|
58
|
+
this.$state.set('HAVING', '');
|
|
59
|
+
if ((options === null || options === void 0 ? void 0 : options.orderBy) != null && options.orderBy)
|
|
60
|
+
this.$state.set('ORDER_BY', []);
|
|
61
|
+
if ((options === null || options === void 0 ? void 0 : options.limit) != null && options.limit)
|
|
62
|
+
this.$state.set('LIMIT', '');
|
|
63
|
+
if ((options === null || options === void 0 ? void 0 : options.offset) != null && options.offset)
|
|
64
|
+
this.$state.set('OFFSET', '');
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
43
67
|
/**
|
|
44
68
|
* The 'distinct' method is used to apply the DISTINCT keyword to a database query.
|
|
45
69
|
*
|
|
@@ -2738,9 +2762,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2738
2762
|
exists() {
|
|
2739
2763
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2740
2764
|
var _a;
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2765
|
+
const sql = new Builder()
|
|
2766
|
+
.copyBuilder(this, { where: true, limit: true, join: true })
|
|
2767
|
+
.selectRaw('1')
|
|
2768
|
+
.limit(1)
|
|
2769
|
+
.toString();
|
|
2744
2770
|
const result = yield this._queryStatement([
|
|
2745
2771
|
`${this.$constants('SELECT')}`,
|
|
2746
2772
|
`${this.$constants('EXISTS')}`,
|
|
@@ -3230,15 +3256,16 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3230
3256
|
].join(' ');
|
|
3231
3257
|
const fields = yield this._queryStatement(sql);
|
|
3232
3258
|
const fakers = [];
|
|
3259
|
+
const uuid = 'uuid';
|
|
3260
|
+
const passed = (field) => ['id', '_id'].some(p => field === p);
|
|
3233
3261
|
for (let row = 0; row < rows; row++) {
|
|
3234
3262
|
let columnAndValue = {};
|
|
3235
3263
|
for (const { Field: field, Type: type } of fields) {
|
|
3236
|
-
|
|
3237
|
-
field.toLowerCase() === '_id' ||
|
|
3238
|
-
field.toLowerCase() === 'uuid';
|
|
3239
|
-
if (passed)
|
|
3264
|
+
if (passed(field))
|
|
3240
3265
|
continue;
|
|
3241
|
-
columnAndValue = Object.assign(Object.assign({}, columnAndValue), { [field]:
|
|
3266
|
+
columnAndValue = Object.assign(Object.assign({}, columnAndValue), { [field]: field === uuid
|
|
3267
|
+
? this.$utils.faker('uuid')
|
|
3268
|
+
: this.$utils.faker(type) });
|
|
3242
3269
|
}
|
|
3243
3270
|
if (cb) {
|
|
3244
3271
|
fakers.push(cb(columnAndValue, row));
|
|
@@ -3251,7 +3278,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3251
3278
|
const table = this.getTableName();
|
|
3252
3279
|
for (const data of chunkedData) {
|
|
3253
3280
|
promises.push(() => {
|
|
3254
|
-
return new DB_1.DB(table).createMultiple([...data]).void().save();
|
|
3281
|
+
return new DB_1.DB(table).dd(this.$state.get('DEBUG')).createMultiple([...data]).void().save();
|
|
3255
3282
|
});
|
|
3256
3283
|
}
|
|
3257
3284
|
yield Promise.allSettled(promises.map((v) => v()));
|
|
@@ -3458,6 +3485,14 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3458
3485
|
this.$logger.reset();
|
|
3459
3486
|
return data;
|
|
3460
3487
|
}
|
|
3488
|
+
_resultHandlerExists(data) {
|
|
3489
|
+
if (!this.$state.get('VOID')) {
|
|
3490
|
+
this.$state.set('RESULT', data);
|
|
3491
|
+
}
|
|
3492
|
+
this.$state.reset();
|
|
3493
|
+
this.$logger.reset();
|
|
3494
|
+
return data;
|
|
3495
|
+
}
|
|
3461
3496
|
whereReference(tableAndLocalKey, tableAndForeignKey) {
|
|
3462
3497
|
this.$state.set('WHERE', [
|
|
3463
3498
|
...this.$state.get('WHERE'),
|