tspace-mysql 1.2.9 → 1.3.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 +64 -14
- package/dist/cli/dump/db.d.ts +4 -4
- package/dist/cli/dump/db.js +25 -25
- package/dist/cli/generate/make.d.ts +4 -4
- package/dist/cli/generate/make.js +45 -45
- package/dist/cli/generate/model.d.ts +2 -2
- package/dist/cli/generate/model.js +6 -6
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +58 -58
- package/dist/cli/migrate/make.d.ts +4 -4
- package/dist/cli/migrate/make.js +30 -30
- package/dist/cli/models/make.d.ts +4 -4
- package/dist/cli/models/make.js +51 -51
- package/dist/cli/models/model.d.ts +2 -2
- package/dist/cli/models/model.js +20 -11
- package/dist/cli/query/index.d.ts +4 -4
- package/dist/cli/query/index.js +7 -7
- package/dist/cli/tables/make.d.ts +4 -4
- package/dist/cli/tables/make.js +26 -26
- package/dist/cli/tables/table.d.ts +2 -2
- package/dist/cli/tables/table.js +6 -6
- package/dist/lib/connection/index.d.ts +30 -30
- package/dist/lib/connection/index.js +144 -143
- package/dist/lib/connection/options.d.ts +15 -4
- package/dist/lib/connection/options.js +43 -42
- package/dist/lib/constants/index.d.ts +5 -8
- package/dist/lib/constants/index.js +162 -158
- package/dist/lib/index.d.ts +8 -8
- package/dist/lib/index.js +36 -36
- package/dist/lib/tspace/{AbstractDatabase.d.ts → AbstractBuilder.d.ts} +124 -116
- package/dist/lib/tspace/{AbstractDatabase.js → AbstractBuilder.js} +36 -34
- package/dist/lib/tspace/AbstractDB.d.ts +18 -18
- package/dist/lib/tspace/AbstractDB.js +11 -11
- package/dist/lib/tspace/AbstractModel.d.ts +41 -41
- package/dist/lib/tspace/AbstractModel.js +11 -11
- package/dist/lib/tspace/Blueprint.d.ts +136 -136
- package/dist/lib/tspace/Blueprint.js +228 -228
- package/dist/lib/tspace/{Database.d.ts → Builder.d.ts} +833 -706
- package/dist/lib/tspace/{Database.js → Builder.js} +2556 -2363
- package/dist/lib/tspace/DB.d.ts +152 -126
- package/dist/lib/tspace/DB.js +373 -264
- package/dist/lib/tspace/Interface.d.ts +110 -109
- package/dist/lib/tspace/Interface.js +2 -2
- package/dist/lib/tspace/Logger.d.ts +8 -8
- package/dist/lib/tspace/Logger.js +49 -49
- package/dist/lib/tspace/Model.d.ts +708 -609
- package/dist/lib/tspace/Model.js +2520 -2477
- package/dist/lib/tspace/ProxyHandler.d.ts +14 -14
- package/dist/lib/tspace/ProxyHandler.js +31 -31
- package/dist/lib/tspace/Schema.d.ts +8 -8
- package/dist/lib/tspace/Schema.js +45 -44
- package/dist/lib/tspace/index.d.ts +15 -15
- package/dist/lib/tspace/index.js +20 -20
- package/dist/lib/utils/index.d.ts +15 -15
- package/dist/lib/utils/index.js +155 -165
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -27,14 +27,14 @@ npm install tspace-mysql --save
|
|
|
27
27
|
- [Belongs To](#belongs-to)
|
|
28
28
|
- [Many To Many](#many-to-many)
|
|
29
29
|
- [Relation in Relation](#relation-in-relation)
|
|
30
|
+
- [Built in Relation Functions](#built-in-relation-functions)
|
|
30
31
|
- [Query Builder](#query-builder)
|
|
31
32
|
- [Cli](#cli)
|
|
32
33
|
- [Make Model](#make-model)
|
|
33
34
|
- [Make Migration](#make-migration)
|
|
34
35
|
- [Migrate](#migrate)
|
|
35
36
|
- [Query](#query)
|
|
36
|
-
- [
|
|
37
|
-
- [Dump Database](#dump-database)
|
|
37
|
+
- [Menerate Models](#generate-models)
|
|
38
38
|
- [Blueprint](#blueprint)
|
|
39
39
|
|
|
40
40
|
## Configuration
|
|
@@ -125,8 +125,11 @@ const users = await new DB('users').where('id','!=',1).findMany()
|
|
|
125
125
|
const whereIn = await new DB('users').whereIn('id',[1,2]).findMany()
|
|
126
126
|
const whereBetween = await new DB('users').whereBetween('id',[1,2]).findMany()
|
|
127
127
|
const whereSubQuery = await new DB('users').whereSubQuery('id','select id from users').findMany()
|
|
128
|
-
// await new DB('users').whereSubQuery('id',new DB('users').select('id').toString()).findMany()
|
|
128
|
+
// same As await new DB('users').whereSubQuery('id',new DB('users').select('id').toString()).findMany()
|
|
129
129
|
const whereNull = await new DB('users').whereNull('username').findOne()
|
|
130
|
+
const whereNotNull = await new DB('users').whereNotNull('username').findOne()
|
|
131
|
+
const whereQuery = await new DB('users').whereQuery(query => query.where('id',1).where('username','tspace')).whereIn('id',[1,2]).findOne()
|
|
132
|
+
// SELECT * FROM `users` WHERE ( `users`.`id` = '1' AND `users`.`username` = 'tspace') AND `users`.`id` IN ('1','2'') LIMIT 1
|
|
130
133
|
```
|
|
131
134
|
|
|
132
135
|
Running A Hook Query
|
|
@@ -173,12 +176,22 @@ const users = await new DB('users')
|
|
|
173
176
|
.where('name','tspace4')
|
|
174
177
|
.where('email','tspace4@gmail.com')
|
|
175
178
|
.createNotExists({
|
|
176
|
-
|
|
177
|
-
|
|
179
|
+
name :'tspace4',
|
|
180
|
+
email : 'tspace4@gmail.com'
|
|
178
181
|
})
|
|
179
182
|
.save()
|
|
180
183
|
// if has exists return null, if not exists created new data
|
|
181
184
|
|
|
185
|
+
const users = await new DB('users')
|
|
186
|
+
.where('name','tspace4')
|
|
187
|
+
.where('email','tspace4@gmail.com')
|
|
188
|
+
.createOrSelect({
|
|
189
|
+
name :'tspace4',
|
|
190
|
+
email : 'tspace4@gmail.com'
|
|
191
|
+
})
|
|
192
|
+
.save()
|
|
193
|
+
// if has exists return data, if not exists created new data
|
|
194
|
+
|
|
182
195
|
```
|
|
183
196
|
Running A Update Query
|
|
184
197
|
```js
|
|
@@ -375,15 +388,17 @@ class User extends Model {
|
|
|
375
388
|
* this.useTable('users')
|
|
376
389
|
* this.useTableSingular() // 'user'
|
|
377
390
|
* this.useTablePlural() // 'users'
|
|
378
|
-
* this.usePattern('snake_case')
|
|
391
|
+
* this.usePattern('snake_case')
|
|
379
392
|
* this.useUUID('uuid') // => runing a uuid (universally unique identifier) when insert new data
|
|
380
393
|
* this.useRegistry()
|
|
394
|
+
* this.useLoadRelationInRegistry()
|
|
395
|
+
* this.useBuiltInRelationFunctions()
|
|
381
396
|
* this.useSchema({
|
|
382
397
|
* id : Number,
|
|
383
398
|
* username : String
|
|
384
399
|
* created_at : Date,
|
|
385
400
|
* updated_at : Date,
|
|
386
|
-
* }) // validate type of schema when return
|
|
401
|
+
* }) // validate type of schema when return results
|
|
387
402
|
*/
|
|
388
403
|
|
|
389
404
|
/*
|
|
@@ -589,6 +604,48 @@ await new User().relations('posts')
|
|
|
589
604
|
.findMany()
|
|
590
605
|
```
|
|
591
606
|
|
|
607
|
+
## Built in Relation Functions
|
|
608
|
+
Relationships can using built in function in results
|
|
609
|
+
let's example a built in function :
|
|
610
|
+
```js
|
|
611
|
+
import { Model } from 'tspace-mysql'
|
|
612
|
+
|
|
613
|
+
class User extends Model {
|
|
614
|
+
constructor(){
|
|
615
|
+
super()
|
|
616
|
+
this.hasMany({ name : 'posts' , model : Post })
|
|
617
|
+
this.useBuiltInRelationFunctions()
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
+--------------------------------------------------------------------------+
|
|
621
|
+
class Post extends Model {
|
|
622
|
+
constructor(){
|
|
623
|
+
super()
|
|
624
|
+
this.hasMany({ name : 'comments' , model : Comment })
|
|
625
|
+
this.belongsTo({ name : 'user' , model : User })
|
|
626
|
+
this.useBuiltInRelationFunctions()
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
+--------------------------------------------------------------------------+
|
|
630
|
+
class Comment extends Model {
|
|
631
|
+
constructor(){
|
|
632
|
+
super()
|
|
633
|
+
this.hasMany({ name : 'users' , model : User })
|
|
634
|
+
this.belongsTo({ name : 'post' , model : Post })
|
|
635
|
+
this.useBuiltInRelationFunctions()
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
+--------------------------------------------------------------------------+
|
|
639
|
+
const user = await new User().findOne()
|
|
640
|
+
const posts = await user.$posts()
|
|
641
|
+
|
|
642
|
+
/** Warning built in function has Big-O effect */
|
|
643
|
+
for (const post of posts) {
|
|
644
|
+
const comments = await post.$comments()
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
```
|
|
648
|
+
|
|
592
649
|
## Query Builder
|
|
593
650
|
Methods builder for queries
|
|
594
651
|
```js
|
|
@@ -777,13 +834,6 @@ tspace-mysql generate:models
|
|
|
777
834
|
|
|
778
835
|
```
|
|
779
836
|
|
|
780
|
-
# Dump Database
|
|
781
|
-
Command will be dump database to .sql
|
|
782
|
-
```js
|
|
783
|
-
tspace-mysql dump:db
|
|
784
|
-
|
|
785
|
-
```
|
|
786
|
-
|
|
787
837
|
## Blueprint
|
|
788
838
|
Schema table created by command make:migration, you may use the:
|
|
789
839
|
```js
|
package/dist/cli/dump/db.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const _default: (cmd: {
|
|
2
|
-
[x: string]: any;
|
|
3
|
-
}) => void;
|
|
4
|
-
export default _default;
|
|
1
|
+
declare const _default: (cmd: {
|
|
2
|
+
[x: string]: any;
|
|
3
|
+
}) => void;
|
|
4
|
+
export default _default;
|
package/dist/cli/dump/db.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const lib_1 = require("../../lib");
|
|
4
|
-
exports.default = (cmd) => {
|
|
5
|
-
const { dir, cwd, fs, db
|
|
6
|
-
if (dir) {
|
|
7
|
-
try {
|
|
8
|
-
fs.accessSync(cwd + `/${dir}`, fs.F_OK, {
|
|
9
|
-
recursive: true
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
catch (e) {
|
|
13
|
-
fs.mkdirSync(cwd + `/${dir}`, {
|
|
14
|
-
recursive: true
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
const directory = `${cwd}/${dir}/dump_${+new Date()}.sql`;
|
|
19
|
-
new lib_1.DB().backupToFile({
|
|
20
|
-
filePath: directory,
|
|
21
|
-
database: db
|
|
22
|
-
})
|
|
23
|
-
.then(r => console.log('dump file successfully'))
|
|
24
|
-
.catch(err => console.log(err));
|
|
25
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const lib_1 = require("../../lib");
|
|
4
|
+
exports.default = (cmd) => {
|
|
5
|
+
const { dir, cwd, fs, db } = cmd;
|
|
6
|
+
if (dir) {
|
|
7
|
+
try {
|
|
8
|
+
fs.accessSync(cwd + `/${dir}`, fs.F_OK, {
|
|
9
|
+
recursive: true
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
fs.mkdirSync(cwd + `/${dir}`, {
|
|
14
|
+
recursive: true
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const directory = `${cwd}/${dir}/dump_${+new Date()}.sql`;
|
|
19
|
+
new lib_1.DB().backupToFile({
|
|
20
|
+
filePath: directory,
|
|
21
|
+
database: db
|
|
22
|
+
})
|
|
23
|
+
.then(r => console.log('dump file successfully'))
|
|
24
|
+
.catch(err => console.log(err));
|
|
25
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const _default: (cmd: {
|
|
2
|
-
[x: string]: any;
|
|
3
|
-
}) => void;
|
|
4
|
-
export default _default;
|
|
1
|
+
declare const _default: (cmd: {
|
|
2
|
+
[x: string]: any;
|
|
3
|
+
}) => void;
|
|
4
|
+
export default _default;
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const model_1 = __importDefault(require("./model"));
|
|
7
|
-
const pluralize_1 = __importDefault(require("pluralize"));
|
|
8
|
-
const lib_1 = require("../../lib");
|
|
9
|
-
exports.default = (cmd) => {
|
|
10
|
-
const { dir, cwd, type, fs, npm } = cmd;
|
|
11
|
-
if (dir) {
|
|
12
|
-
try {
|
|
13
|
-
fs.accessSync(cwd + `/${dir}`, fs.F_OK, {
|
|
14
|
-
recursive: true
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
catch (e) {
|
|
18
|
-
fs.mkdirSync(cwd + `/${dir}`, {
|
|
19
|
-
recursive: true
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
const snakeCaseToPascal = (data) => {
|
|
24
|
-
let str = data.split('_');
|
|
25
|
-
for (let i = 0; i < str.length; i++) {
|
|
26
|
-
str[i] = str[i].slice(0, 1).toUpperCase() + str[i].slice(1, str[i].length);
|
|
27
|
-
}
|
|
28
|
-
return str.join('');
|
|
29
|
-
};
|
|
30
|
-
new lib_1.DB().rawQuery('SHOW TABLES').then(tables => {
|
|
31
|
-
var _a;
|
|
32
|
-
for (let i = 0; i < tables.length; i++) {
|
|
33
|
-
const table = String((_a = Object.values(tables[i])) === null || _a === void 0 ? void 0 : _a.shift());
|
|
34
|
-
const model = snakeCaseToPascal(pluralize_1.default.singular(table));
|
|
35
|
-
const data = (0, model_1.default)(model, npm);
|
|
36
|
-
fs.writeFile(`${cwd}/${dir}/${model}${type !== null && type !== void 0 ? type : '.ts'}`, data, (err) => {
|
|
37
|
-
if (err)
|
|
38
|
-
throw err;
|
|
39
|
-
});
|
|
40
|
-
console.log(`Model : '${model}' created successfully`);
|
|
41
|
-
}
|
|
42
|
-
console.log('\nGenerate Models has completed');
|
|
43
|
-
})
|
|
44
|
-
.catch(err => console.log(err));
|
|
45
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const model_1 = __importDefault(require("./model"));
|
|
7
|
+
const pluralize_1 = __importDefault(require("pluralize"));
|
|
8
|
+
const lib_1 = require("../../lib");
|
|
9
|
+
exports.default = (cmd) => {
|
|
10
|
+
const { dir, cwd, type, fs, npm } = cmd;
|
|
11
|
+
if (dir) {
|
|
12
|
+
try {
|
|
13
|
+
fs.accessSync(cwd + `/${dir}`, fs.F_OK, {
|
|
14
|
+
recursive: true
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
fs.mkdirSync(cwd + `/${dir}`, {
|
|
19
|
+
recursive: true
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const snakeCaseToPascal = (data) => {
|
|
24
|
+
let str = data.split('_');
|
|
25
|
+
for (let i = 0; i < str.length; i++) {
|
|
26
|
+
str[i] = str[i].slice(0, 1).toUpperCase() + str[i].slice(1, str[i].length);
|
|
27
|
+
}
|
|
28
|
+
return str.join('');
|
|
29
|
+
};
|
|
30
|
+
new lib_1.DB().rawQuery('SHOW TABLES').then(tables => {
|
|
31
|
+
var _a;
|
|
32
|
+
for (let i = 0; i < tables.length; i++) {
|
|
33
|
+
const table = String((_a = Object.values(tables[i])) === null || _a === void 0 ? void 0 : _a.shift());
|
|
34
|
+
const model = snakeCaseToPascal(pluralize_1.default.singular(table));
|
|
35
|
+
const data = (0, model_1.default)(model, npm);
|
|
36
|
+
fs.writeFile(`${cwd}/${dir}/${model}${type !== null && type !== void 0 ? type : '.ts'}`, data, (err) => {
|
|
37
|
+
if (err)
|
|
38
|
+
throw err;
|
|
39
|
+
});
|
|
40
|
+
console.log(`Model : '${model}' created successfully`);
|
|
41
|
+
}
|
|
42
|
+
console.log('\nGenerate Models has completed');
|
|
43
|
+
})
|
|
44
|
+
.catch(err => console.log(err));
|
|
45
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const Model: (model: string, npm: string) => string;
|
|
2
|
-
export default Model;
|
|
1
|
+
declare const Model: (model: string, npm: string) => string;
|
|
2
|
+
export default Model;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const Model = (model, npm) => {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Model = (model, npm) => {
|
|
4
4
|
return `import { Model } from '${npm}'
|
|
5
5
|
class ${model} extends Model {
|
|
6
6
|
constructor(){
|
|
@@ -25,6 +25,6 @@ class ${model} extends Model {
|
|
|
25
25
|
}
|
|
26
26
|
export { ${model} }
|
|
27
27
|
export default ${model}
|
|
28
|
-
`;
|
|
29
|
-
};
|
|
30
|
-
exports.default = Model;
|
|
28
|
+
`;
|
|
29
|
+
};
|
|
30
|
+
exports.default = Model;
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
export {};
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export {};
|
package/dist/cli/index.js
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const make_1 = __importDefault(require("./models/make"));
|
|
10
|
-
const make_2 = __importDefault(require("./tables/make"));
|
|
11
|
-
const make_3 = __importDefault(require("./migrate/make"));
|
|
12
|
-
const make_4 = __importDefault(require("./generate/make"));
|
|
13
|
-
const query_1 = __importDefault(require("./query"));
|
|
14
|
-
const db_1 = __importDefault(require("./dump/db"));
|
|
15
|
-
const commands = {
|
|
16
|
-
'query': query_1.default,
|
|
17
|
-
'make:model': make_1.default,
|
|
18
|
-
'make:table': make_2.default,
|
|
19
|
-
'make:migration': make_2.default,
|
|
20
|
-
'migrate': make_3.default,
|
|
21
|
-
'generate:models': make_4.default,
|
|
22
|
-
'dump:db': db_1.default,
|
|
23
|
-
};
|
|
24
|
-
try {
|
|
25
|
-
const name = (_c = (_b = (_a = process.argv.slice(2)) === null || _a === void 0 ? void 0 : _a.find(data => {
|
|
26
|
-
return data === null || data === void 0 ? void 0 : data.includes('--name=');
|
|
27
|
-
})) === null || _b === void 0 ? void 0 : _b.replace('--name=', '')) !== null && _c !== void 0 ? _c : null;
|
|
28
|
-
const sql = (_d = process.argv.slice(3)[0]) !== null && _d !== void 0 ? _d : '';
|
|
29
|
-
const migrate = (_f = (_e = process.argv.slice(2)) === null || _e === void 0 ? void 0 : _e.includes('--m')) !== null && _f !== void 0 ? _f : false;
|
|
30
|
-
const dir = (_j = (_h = (_g = process.argv.slice(2)) === null || _g === void 0 ? void 0 : _g.find(data => {
|
|
31
|
-
return data === null || data === void 0 ? void 0 : data.includes('--dir=');
|
|
32
|
-
})) === null || _h === void 0 ? void 0 : _h.replace('--dir=', '/')) !== null && _j !== void 0 ? _j : null;
|
|
33
|
-
const db = (_m = (_l = (_k = process.argv.slice(2)) === null || _k === void 0 ? void 0 : _k.find(data => {
|
|
34
|
-
return data === null || data === void 0 ? void 0 : data.includes('--db=');
|
|
35
|
-
})) === null || _l === void 0 ? void 0 : _l.replace('--db=', '')) !== null && _m !== void 0 ? _m : null;
|
|
36
|
-
let type = (_q = (_p = (_o = process.argv.slice(2)) === null || _o === void 0 ? void 0 : _o.find(data => {
|
|
37
|
-
return data === null || data === void 0 ? void 0 : data.includes('--type=');
|
|
38
|
-
})) === null || _p === void 0 ? void 0 : _p.replace('--type=', '.')) !== null && _q !== void 0 ? _q : '.ts';
|
|
39
|
-
type = ['.js', '.ts'].includes(type) ? type : '.ts';
|
|
40
|
-
const file = (_r = process.argv.slice(3)[0]) !== null && _r !== void 0 ? _r : '';
|
|
41
|
-
const cmd = {
|
|
42
|
-
name,
|
|
43
|
-
file,
|
|
44
|
-
dir,
|
|
45
|
-
migrate,
|
|
46
|
-
type,
|
|
47
|
-
cwd: process.cwd(),
|
|
48
|
-
fs: fs_1.default,
|
|
49
|
-
sql,
|
|
50
|
-
db,
|
|
51
|
-
npm: 'tspace-mysql'
|
|
52
|
-
};
|
|
53
|
-
commands[process.argv[2]](cmd);
|
|
54
|
-
}
|
|
55
|
-
catch (err) {
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const make_1 = __importDefault(require("./models/make"));
|
|
10
|
+
const make_2 = __importDefault(require("./tables/make"));
|
|
11
|
+
const make_3 = __importDefault(require("./migrate/make"));
|
|
12
|
+
const make_4 = __importDefault(require("./generate/make"));
|
|
13
|
+
const query_1 = __importDefault(require("./query"));
|
|
14
|
+
const db_1 = __importDefault(require("./dump/db"));
|
|
15
|
+
const commands = {
|
|
16
|
+
'query': query_1.default,
|
|
17
|
+
'make:model': make_1.default,
|
|
18
|
+
'make:table': make_2.default,
|
|
19
|
+
'make:migration': make_2.default,
|
|
20
|
+
'migrate': make_3.default,
|
|
21
|
+
'generate:models': make_4.default,
|
|
22
|
+
'dump:db': db_1.default,
|
|
23
|
+
};
|
|
24
|
+
try {
|
|
25
|
+
const name = (_c = (_b = (_a = process.argv.slice(2)) === null || _a === void 0 ? void 0 : _a.find(data => {
|
|
26
|
+
return data === null || data === void 0 ? void 0 : data.includes('--name=');
|
|
27
|
+
})) === null || _b === void 0 ? void 0 : _b.replace('--name=', '')) !== null && _c !== void 0 ? _c : null;
|
|
28
|
+
const sql = (_d = process.argv.slice(3)[0]) !== null && _d !== void 0 ? _d : '';
|
|
29
|
+
const migrate = (_f = (_e = process.argv.slice(2)) === null || _e === void 0 ? void 0 : _e.includes('--m')) !== null && _f !== void 0 ? _f : false;
|
|
30
|
+
const dir = (_j = (_h = (_g = process.argv.slice(2)) === null || _g === void 0 ? void 0 : _g.find(data => {
|
|
31
|
+
return data === null || data === void 0 ? void 0 : data.includes('--dir=');
|
|
32
|
+
})) === null || _h === void 0 ? void 0 : _h.replace('--dir=', '/')) !== null && _j !== void 0 ? _j : null;
|
|
33
|
+
const db = (_m = (_l = (_k = process.argv.slice(2)) === null || _k === void 0 ? void 0 : _k.find(data => {
|
|
34
|
+
return data === null || data === void 0 ? void 0 : data.includes('--db=');
|
|
35
|
+
})) === null || _l === void 0 ? void 0 : _l.replace('--db=', '')) !== null && _m !== void 0 ? _m : null;
|
|
36
|
+
let type = (_q = (_p = (_o = process.argv.slice(2)) === null || _o === void 0 ? void 0 : _o.find(data => {
|
|
37
|
+
return data === null || data === void 0 ? void 0 : data.includes('--type=');
|
|
38
|
+
})) === null || _p === void 0 ? void 0 : _p.replace('--type=', '.')) !== null && _q !== void 0 ? _q : '.ts';
|
|
39
|
+
type = ['.js', '.ts'].includes(type) ? type : '.ts';
|
|
40
|
+
const file = (_r = process.argv.slice(3)[0]) !== null && _r !== void 0 ? _r : '';
|
|
41
|
+
const cmd = {
|
|
42
|
+
name,
|
|
43
|
+
file,
|
|
44
|
+
dir,
|
|
45
|
+
migrate,
|
|
46
|
+
type,
|
|
47
|
+
cwd: process.cwd(),
|
|
48
|
+
fs: fs_1.default,
|
|
49
|
+
sql,
|
|
50
|
+
db,
|
|
51
|
+
npm: 'tspace-mysql'
|
|
52
|
+
};
|
|
53
|
+
commands[process.argv[2]](cmd);
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
56
|
console.log(`
|
|
57
57
|
tspace-mysql make:model User --m --dir=app/Models
|
|
58
58
|
tspace-mysql make:migration users --dir=app/Models/Migrations
|
|
@@ -60,6 +60,6 @@ catch (err) {
|
|
|
60
60
|
tspace-mysql query "SELECT * FROM users"
|
|
61
61
|
tspace-mysql generate:models --dir=app/Models
|
|
62
62
|
tspace-mysql dump:db --dir=app/Models
|
|
63
|
-
`);
|
|
64
|
-
console.log(`Read more https://www.npmjs.com/package/tspace-mysql`);
|
|
65
|
-
}
|
|
63
|
+
`);
|
|
64
|
+
console.log(`Read more https://www.npmjs.com/package/tspace-mysql`);
|
|
65
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const _default: (formCommand: {
|
|
2
|
-
[x: string]: any;
|
|
3
|
-
}) => void;
|
|
4
|
-
export default _default;
|
|
1
|
+
declare const _default: (formCommand: {
|
|
2
|
+
[x: string]: any;
|
|
3
|
+
}) => void;
|
|
4
|
+
export default _default;
|
package/dist/cli/migrate/make.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const child_process_1 = require("child_process");
|
|
4
|
-
exports.default = (formCommand) => {
|
|
5
|
-
var _a, _b, _c;
|
|
6
|
-
const { type, dir, cwd, fs } = formCommand;
|
|
7
|
-
try {
|
|
8
|
-
if (dir == null)
|
|
9
|
-
throw new Error('Not found directory');
|
|
10
|
-
const path = `${cwd}/${dir}`;
|
|
11
|
-
const files = (_a = fs.readdirSync(path)) !== null && _a !== void 0 ? _a : [];
|
|
12
|
-
if (!(files === null || files === void 0 ? void 0 : files.length))
|
|
13
|
-
console.log('this folder is empty');
|
|
14
|
-
const cmd = type === '.js' ? 'node' : 'ts-node';
|
|
15
|
-
for (const _file of files) {
|
|
16
|
-
const run = (0, child_process_1.exec)(`${cmd} ${path}/${_file}`);
|
|
17
|
-
(_b = run === null || run === void 0 ? void 0 : run.stdout) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
18
|
-
if (data)
|
|
19
|
-
console.log(data);
|
|
20
|
-
});
|
|
21
|
-
(_c = run === null || run === void 0 ? void 0 : run.stderr) === null || _c === void 0 ? void 0 : _c.on('data', (err) => {
|
|
22
|
-
if (err)
|
|
23
|
-
console.error(err);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
catch (err) {
|
|
28
|
-
console.log(err.message);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const child_process_1 = require("child_process");
|
|
4
|
+
exports.default = (formCommand) => {
|
|
5
|
+
var _a, _b, _c;
|
|
6
|
+
const { type, dir, cwd, fs } = formCommand;
|
|
7
|
+
try {
|
|
8
|
+
if (dir == null)
|
|
9
|
+
throw new Error('Not found directory');
|
|
10
|
+
const path = `${cwd}/${dir}`;
|
|
11
|
+
const files = (_a = fs.readdirSync(path)) !== null && _a !== void 0 ? _a : [];
|
|
12
|
+
if (!(files === null || files === void 0 ? void 0 : files.length))
|
|
13
|
+
console.log('this folder is empty');
|
|
14
|
+
const cmd = type === '.js' ? 'node' : 'ts-node';
|
|
15
|
+
for (const _file of files) {
|
|
16
|
+
const run = (0, child_process_1.exec)(`${cmd} ${path}/${_file}`);
|
|
17
|
+
(_b = run === null || run === void 0 ? void 0 : run.stdout) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
18
|
+
if (data)
|
|
19
|
+
console.log(data);
|
|
20
|
+
});
|
|
21
|
+
(_c = run === null || run === void 0 ? void 0 : run.stderr) === null || _c === void 0 ? void 0 : _c.on('data', (err) => {
|
|
22
|
+
if (err)
|
|
23
|
+
console.error(err);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
console.log(err.message);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const _default: (cmd: {
|
|
2
|
-
[x: string]: any;
|
|
3
|
-
}) => void;
|
|
4
|
-
export default _default;
|
|
1
|
+
declare const _default: (cmd: {
|
|
2
|
+
[x: string]: any;
|
|
3
|
+
}) => void;
|
|
4
|
+
export default _default;
|
package/dist/cli/models/make.js
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const model_1 = __importDefault(require("./model"));
|
|
7
|
-
const table_1 = __importDefault(require("../tables/table"));
|
|
8
|
-
const pluralize_1 = __importDefault(require("pluralize"));
|
|
9
|
-
exports.default = (cmd) => {
|
|
10
|
-
const { file, migrate, dir, type, cwd, fs, npm } = cmd;
|
|
11
|
-
if (dir) {
|
|
12
|
-
try {
|
|
13
|
-
fs.accessSync(cwd + `/${dir}`, fs.F_OK, {
|
|
14
|
-
recursive: true
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
catch (e) {
|
|
18
|
-
fs.mkdirSync(cwd + `/${dir}`, {
|
|
19
|
-
recursive: true
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
const model = dir ? `${cwd}/${dir}/${file}${type}` : `${cwd}/${file}${type}`;
|
|
24
|
-
const data = (0, model_1.default)(file, npm);
|
|
25
|
-
fs.writeFile(model, data, (err) => {
|
|
26
|
-
if (err)
|
|
27
|
-
throw err.message;
|
|
28
|
-
});
|
|
29
|
-
console.log(`Model : '${file}' created successfully`);
|
|
30
|
-
if (migrate) {
|
|
31
|
-
const tableName = (0, pluralize_1.default)(file.replace(/([A-Z])/g, (str) => '_' + str.toLowerCase()).slice(1));
|
|
32
|
-
const folder = dir ? `${dir}/Migrations` : `/Migrations`;
|
|
33
|
-
try {
|
|
34
|
-
fs.accessSync(cwd + folder, fs.F_OK, {
|
|
35
|
-
recursive: true
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
catch (e) {
|
|
39
|
-
fs.mkdirSync(cwd + folder, {
|
|
40
|
-
recursive: true
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
const folderMigrate = `${cwd}/${folder}/create_${tableName}_table${type}`;
|
|
44
|
-
const table = (0, table_1.default)(tableName, npm);
|
|
45
|
-
fs.writeFile(folderMigrate, table, (err) => {
|
|
46
|
-
if (err)
|
|
47
|
-
throw err;
|
|
48
|
-
});
|
|
49
|
-
console.log(`Migration : '${tableName}' created successfully`);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const model_1 = __importDefault(require("./model"));
|
|
7
|
+
const table_1 = __importDefault(require("../tables/table"));
|
|
8
|
+
const pluralize_1 = __importDefault(require("pluralize"));
|
|
9
|
+
exports.default = (cmd) => {
|
|
10
|
+
const { file, migrate, dir, type, cwd, fs, npm } = cmd;
|
|
11
|
+
if (dir) {
|
|
12
|
+
try {
|
|
13
|
+
fs.accessSync(cwd + `/${dir}`, fs.F_OK, {
|
|
14
|
+
recursive: true
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
fs.mkdirSync(cwd + `/${dir}`, {
|
|
19
|
+
recursive: true
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const model = dir ? `${cwd}/${dir}/${file}${type}` : `${cwd}/${file}${type}`;
|
|
24
|
+
const data = (0, model_1.default)(file, npm);
|
|
25
|
+
fs.writeFile(model, data, (err) => {
|
|
26
|
+
if (err)
|
|
27
|
+
throw err.message;
|
|
28
|
+
});
|
|
29
|
+
console.log(`Model : '${file}' created successfully`);
|
|
30
|
+
if (migrate) {
|
|
31
|
+
const tableName = (0, pluralize_1.default)(file.replace(/([A-Z])/g, (str) => '_' + str.toLowerCase()).slice(1));
|
|
32
|
+
const folder = dir ? `${dir}/Migrations` : `/Migrations`;
|
|
33
|
+
try {
|
|
34
|
+
fs.accessSync(cwd + folder, fs.F_OK, {
|
|
35
|
+
recursive: true
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
fs.mkdirSync(cwd + folder, {
|
|
40
|
+
recursive: true
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const folderMigrate = `${cwd}/${folder}/create_${tableName}_table${type}`;
|
|
44
|
+
const table = (0, table_1.default)(tableName, npm);
|
|
45
|
+
fs.writeFile(folderMigrate, table, (err) => {
|
|
46
|
+
if (err)
|
|
47
|
+
throw err;
|
|
48
|
+
});
|
|
49
|
+
console.log(`Migration : '${tableName}' created successfully`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const Model: (model: string, npm: string) => string;
|
|
2
|
-
export default Model;
|
|
1
|
+
declare const Model: (model: string, npm: string) => string;
|
|
2
|
+
export default Model;
|