tspace-mysql 1.3.0 → 1.3.2
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 +72 -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 +43 -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} +825 -706
- package/dist/lib/tspace/{Database.js → Builder.js} +2548 -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 +2519 -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
|
|
@@ -91,6 +91,8 @@ const selectQuery = await new DB('users').select('id','username').findOne()
|
|
|
91
91
|
const selectQueries = await new DB('users').select('id','username').findMany()
|
|
92
92
|
// selectQueries => [{ id : 1, username : 'tspace' } , { id : 2, username : 'tspace2'}]
|
|
93
93
|
|
|
94
|
+
const selectQueryRaw = await new DB('users').selectRaw('COUNT(id)').findMany()
|
|
95
|
+
|
|
94
96
|
/**
|
|
95
97
|
* @example except
|
|
96
98
|
*/
|
|
@@ -125,8 +127,11 @@ const users = await new DB('users').where('id','!=',1).findMany()
|
|
|
125
127
|
const whereIn = await new DB('users').whereIn('id',[1,2]).findMany()
|
|
126
128
|
const whereBetween = await new DB('users').whereBetween('id',[1,2]).findMany()
|
|
127
129
|
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()
|
|
130
|
+
// same As await new DB('users').whereSubQuery('id',new DB('users').select('id').toString()).findMany()
|
|
129
131
|
const whereNull = await new DB('users').whereNull('username').findOne()
|
|
132
|
+
const whereNotNull = await new DB('users').whereNotNull('username').findOne()
|
|
133
|
+
const whereQuery = await new DB('users').whereQuery(query => query.where('id',1).where('username','tspace')).whereIn('id',[1,2]).findOne()
|
|
134
|
+
// SELECT * FROM `users` WHERE ( `users`.`id` = '1' AND `users`.`username` = 'tspace') AND `users`.`id` IN ('1','2'') LIMIT 1
|
|
130
135
|
```
|
|
131
136
|
|
|
132
137
|
Running A Hook Query
|
|
@@ -173,12 +178,22 @@ const users = await new DB('users')
|
|
|
173
178
|
.where('name','tspace4')
|
|
174
179
|
.where('email','tspace4@gmail.com')
|
|
175
180
|
.createNotExists({
|
|
176
|
-
|
|
177
|
-
|
|
181
|
+
name :'tspace4',
|
|
182
|
+
email : 'tspace4@gmail.com'
|
|
178
183
|
})
|
|
179
184
|
.save()
|
|
180
185
|
// if has exists return null, if not exists created new data
|
|
181
186
|
|
|
187
|
+
const users = await new DB('users')
|
|
188
|
+
.where('name','tspace4')
|
|
189
|
+
.where('email','tspace4@gmail.com')
|
|
190
|
+
.createOrSelect({
|
|
191
|
+
name :'tspace4',
|
|
192
|
+
email : 'tspace4@gmail.com'
|
|
193
|
+
})
|
|
194
|
+
.save()
|
|
195
|
+
// if has exists return data, if not exists created new data
|
|
196
|
+
|
|
182
197
|
```
|
|
183
198
|
Running A Update Query
|
|
184
199
|
```js
|
|
@@ -375,15 +390,17 @@ class User extends Model {
|
|
|
375
390
|
* this.useTable('users')
|
|
376
391
|
* this.useTableSingular() // 'user'
|
|
377
392
|
* this.useTablePlural() // 'users'
|
|
378
|
-
* this.usePattern('snake_case')
|
|
393
|
+
* this.usePattern('snake_case')
|
|
379
394
|
* this.useUUID('uuid') // => runing a uuid (universally unique identifier) when insert new data
|
|
380
395
|
* this.useRegistry()
|
|
396
|
+
* this.useLoadRelationInRegistry()
|
|
397
|
+
* this.useBuiltInRelationFunctions()
|
|
381
398
|
* this.useSchema({
|
|
382
399
|
* id : Number,
|
|
383
400
|
* username : String
|
|
384
401
|
* created_at : Date,
|
|
385
402
|
* updated_at : Date,
|
|
386
|
-
* }) // validate type of schema when return
|
|
403
|
+
* }) // validate type of schema when return results
|
|
387
404
|
*/
|
|
388
405
|
|
|
389
406
|
/*
|
|
@@ -589,6 +606,48 @@ await new User().relations('posts')
|
|
|
589
606
|
.findMany()
|
|
590
607
|
```
|
|
591
608
|
|
|
609
|
+
## Built in Relation Functions
|
|
610
|
+
Relationships can using built in function in results
|
|
611
|
+
let's example a built in function :
|
|
612
|
+
```js
|
|
613
|
+
import { Model } from 'tspace-mysql'
|
|
614
|
+
|
|
615
|
+
class User extends Model {
|
|
616
|
+
constructor(){
|
|
617
|
+
super()
|
|
618
|
+
this.hasMany({ name : 'posts' , model : Post })
|
|
619
|
+
this.useBuiltInRelationFunctions()
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
+--------------------------------------------------------------------------+
|
|
623
|
+
class Post extends Model {
|
|
624
|
+
constructor(){
|
|
625
|
+
super()
|
|
626
|
+
this.hasMany({ name : 'comments' , model : Comment })
|
|
627
|
+
this.belongsTo({ name : 'user' , model : User })
|
|
628
|
+
this.useBuiltInRelationFunctions()
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
+--------------------------------------------------------------------------+
|
|
632
|
+
class Comment extends Model {
|
|
633
|
+
constructor(){
|
|
634
|
+
super()
|
|
635
|
+
this.hasMany({ name : 'users' , model : User })
|
|
636
|
+
this.belongsTo({ name : 'post' , model : Post })
|
|
637
|
+
this.useBuiltInRelationFunctions()
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
+--------------------------------------------------------------------------+
|
|
641
|
+
const user = await new User().findOne()
|
|
642
|
+
const posts = await user.$posts()
|
|
643
|
+
|
|
644
|
+
/** Warning built in function has Big-O effect */
|
|
645
|
+
for (const post of posts) {
|
|
646
|
+
const comments = await post.$comments()
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
```
|
|
650
|
+
|
|
592
651
|
## Query Builder
|
|
593
652
|
Methods builder for queries
|
|
594
653
|
```js
|
|
@@ -612,6 +671,7 @@ orWhereRaw(sql)
|
|
|
612
671
|
orWhereIn(column , [])
|
|
613
672
|
orWhereSubQuery(colmn , rawSQL)
|
|
614
673
|
select(column1 ,column2 ,...N)
|
|
674
|
+
selectRaw(column1 ,column2 ,...N)
|
|
615
675
|
except(column1 ,column2 ,...N)
|
|
616
676
|
only(column1 ,column2 ,...N)
|
|
617
677
|
hidden(column1 ,column2 ,...N)
|
|
@@ -620,10 +680,15 @@ rightJoin (primary key , table.foreign key)
|
|
|
620
680
|
leftJoin (primary key , table.foreign key)
|
|
621
681
|
limit (limit)
|
|
622
682
|
having (condition)
|
|
683
|
+
havingRaw (condition)
|
|
623
684
|
orderBy (column ,'ASC' || 'DSCE')
|
|
685
|
+
orderByRaw(column ,'ASC' || 'DSCE')
|
|
624
686
|
latest (column)
|
|
687
|
+
latestRaw (column)
|
|
625
688
|
oldest (column)
|
|
689
|
+
oldestRaw (column)
|
|
626
690
|
groupBy (column)
|
|
691
|
+
groupByRaw (column)
|
|
627
692
|
create(objects)
|
|
628
693
|
createMultiple(array objects)
|
|
629
694
|
update (objects)
|
|
@@ -777,13 +842,6 @@ tspace-mysql generate:models
|
|
|
777
842
|
|
|
778
843
|
```
|
|
779
844
|
|
|
780
|
-
# Dump Database
|
|
781
|
-
Command will be dump database to .sql
|
|
782
|
-
```js
|
|
783
|
-
tspace-mysql dump:db
|
|
784
|
-
|
|
785
|
-
```
|
|
786
|
-
|
|
787
845
|
## Blueprint
|
|
788
846
|
Schema table created by command make:migration, you may use the:
|
|
789
847
|
```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;
|