tspace-mysql 1.3.8 → 1.4.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 +50 -40
- package/dist/cli/dump/db.js +23 -10
- package/dist/cli/dump/table.d.ts +4 -0
- package/dist/cli/dump/table.js +38 -0
- package/dist/cli/generate/make.js +27 -10
- package/dist/cli/generate/model.d.ts +1 -1
- package/dist/cli/generate/model.js +23 -16
- package/dist/cli/index.js +21 -5
- package/dist/cli/migrate/make.d.ts +1 -1
- package/dist/cli/migrate/make.js +2 -2
- package/dist/cli/models/make.js +2 -2
- package/dist/cli/models/model.js +1 -14
- package/dist/cli/query/index.js +4 -1
- package/dist/lib/connection/options.js +16 -15
- package/dist/lib/constants/index.js +6 -2
- package/dist/lib/tspace/Abstract/AbstractDB.d.ts +1 -1
- package/dist/lib/tspace/Blueprint.d.ts +21 -16
- package/dist/lib/tspace/Blueprint.js +44 -27
- package/dist/lib/tspace/Builder.d.ts +52 -2
- package/dist/lib/tspace/Builder.js +152 -3
- package/dist/lib/tspace/DB.d.ts +12 -12
- package/dist/lib/tspace/DB.js +42 -29
- package/dist/lib/tspace/Interface.d.ts +12 -0
- package/dist/lib/tspace/Model.d.ts +18 -10
- package/dist/lib/tspace/Model.js +85 -74
- package/dist/lib/tspace/Schema.d.ts +1 -1
- package/dist/lib/tspace/Schema.js +7 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com)
|
|
4
4
|
[](https://www.npmjs.com)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
tspace-mysql is an ORM that can run in NodeJs and can be used with TypeScript.
|
|
7
7
|
Its always support the latest TypeScript and JavaScript features and provide additional features that help you to develop.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
@@ -35,6 +35,7 @@ npm install tspace-mysql --save
|
|
|
35
35
|
- [Make Migration](#make-migration)
|
|
36
36
|
- [Migrate](#migrate)
|
|
37
37
|
- [Query](#query)
|
|
38
|
+
- [Dump](#dump)
|
|
38
39
|
- [Generate Models](#generate-models)
|
|
39
40
|
- [Blueprint](#blueprint)
|
|
40
41
|
|
|
@@ -63,7 +64,7 @@ source db {
|
|
|
63
64
|
port = 3306
|
|
64
65
|
database = npm
|
|
65
66
|
user = root
|
|
66
|
-
password =
|
|
67
|
+
password = database
|
|
67
68
|
connectionLimit = 10
|
|
68
69
|
dateStrings = true
|
|
69
70
|
connectTimeout = 60000
|
|
@@ -414,13 +415,7 @@ class User extends Model {
|
|
|
414
415
|
* this.useRegistry() // => build-in functions registry
|
|
415
416
|
* this.useLoadRelationsInRegistry() // => auto generated results from relationship to results
|
|
416
417
|
* this.useBuiltInRelationFunctions() // => build-in functions relationships to results
|
|
417
|
-
* this.
|
|
418
|
-
* id : Number,
|
|
419
|
-
* username : String
|
|
420
|
-
* created_at : Date,
|
|
421
|
-
* updated_at : Date,
|
|
422
|
-
* }) // => validate type of schema when return results
|
|
423
|
-
* this.useCreateTableIfNotExists ({
|
|
418
|
+
* this.useSchema ({
|
|
424
419
|
* id : new Blueprint().int().notNull().primary().autoIncrement(),
|
|
425
420
|
* uuid : new Blueprint().varchar(50).null(),
|
|
426
421
|
* user_id : new Blueprint().int().notNull(),
|
|
@@ -428,7 +423,9 @@ class User extends Model {
|
|
|
428
423
|
* created_at : new Blueprint().timestamp().null(),
|
|
429
424
|
* updated_at : new Blueprint().timestamp().null(),
|
|
430
425
|
* deleted_at : new Blueprint().timestamp().null()
|
|
431
|
-
*
|
|
426
|
+
* }) // auto-generated table when table is not exists and auto-create column when column not exists
|
|
427
|
+
*
|
|
428
|
+
* this.useValidateSchema() // => validate type of value when return results reference to the schema in 'this.useSchema'
|
|
432
429
|
*/
|
|
433
430
|
|
|
434
431
|
|
|
@@ -620,49 +617,54 @@ class Comment extends Model {
|
|
|
620
617
|
}
|
|
621
618
|
+--------------------------------------------------------------------------+
|
|
622
619
|
// Deeply nested relations
|
|
623
|
-
await new User()
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
620
|
+
await new User()
|
|
621
|
+
.relations('posts')
|
|
622
|
+
.relationQuery('posts', (query : Post) => {
|
|
623
|
+
return query.relations('comments','user')
|
|
624
|
+
.relationQuery('comments', (query : Comment) => {
|
|
625
|
+
return query.relations('user','post')
|
|
626
|
+
})
|
|
627
|
+
.relationQuery('user', (query : User) => {
|
|
628
|
+
return query.relations('posts').relationQuery('posts',(query : Post)=> {
|
|
629
|
+
return query.relations('comments','user')
|
|
630
|
+
// relation n, n, ...n
|
|
634
631
|
})
|
|
635
632
|
})
|
|
636
|
-
|
|
633
|
+
})
|
|
634
|
+
.findMany()
|
|
637
635
|
|
|
638
636
|
// Select some columns in nested relations
|
|
639
|
-
await new User()
|
|
640
|
-
|
|
641
|
-
|
|
637
|
+
await new User()
|
|
638
|
+
.relations('posts')
|
|
639
|
+
.relationQuery('posts', (query : Post) => query.select('id','user_id','title'))
|
|
640
|
+
.findMany()
|
|
642
641
|
|
|
643
642
|
// Where some columns in nested relations
|
|
644
|
-
await new User()
|
|
645
|
-
|
|
646
|
-
|
|
643
|
+
await new User()
|
|
644
|
+
.relations('posts')
|
|
645
|
+
.relationQuery('posts', (query : Post) => query.whereIn('id',[1,3,5]))
|
|
646
|
+
.findMany()
|
|
647
647
|
|
|
648
648
|
// Sort data in nested relations
|
|
649
|
-
await new User()
|
|
650
|
-
|
|
651
|
-
|
|
649
|
+
await new User()
|
|
650
|
+
.relations('posts')
|
|
651
|
+
.relationQuery('posts', (query : Post) => query.latest('id'))
|
|
652
|
+
.findMany()
|
|
652
653
|
|
|
653
654
|
// Limit data in nested relations
|
|
654
|
-
await new User()
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
655
|
+
await new User()
|
|
656
|
+
.relations('posts')
|
|
657
|
+
.relationQuery('posts', (query : Post) => {
|
|
658
|
+
return query
|
|
659
|
+
.limit(1)
|
|
660
|
+
.relations('comments')
|
|
661
|
+
.relationQuery('comments', (query : Comment) => query.limit(1))
|
|
662
|
+
})
|
|
663
|
+
.findMany()
|
|
662
664
|
|
|
663
665
|
```
|
|
664
666
|
## Relation Exists
|
|
665
|
-
Relationships can return only result is not
|
|
667
|
+
Relationships can return only result is not empty in relations.
|
|
666
668
|
let's example a exists in relations :
|
|
667
669
|
```js
|
|
668
670
|
+-------------+--------------+----------------------------+--------------------+
|
|
@@ -995,6 +997,14 @@ Command will be execute a query
|
|
|
995
997
|
```js
|
|
996
998
|
tspace-mysql query "SELECT * FROM users"
|
|
997
999
|
|
|
1000
|
+
```
|
|
1001
|
+
# Dump
|
|
1002
|
+
Command will be dump database or table into file
|
|
1003
|
+
```js
|
|
1004
|
+
tspace-mysql dump:db --db=database --values
|
|
1005
|
+
|
|
1006
|
+
tspace-mysql dump:table --table=table --values
|
|
1007
|
+
|
|
998
1008
|
```
|
|
999
1009
|
|
|
1000
1010
|
# Generate Models
|
package/dist/cli/dump/db.js
CHANGED
|
@@ -2,24 +2,37 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const lib_1 = require("../../lib");
|
|
4
4
|
exports.default = (cmd) => {
|
|
5
|
-
const { dir, cwd, fs, db } = cmd;
|
|
5
|
+
const { dir, cwd, fs, values, db } = cmd;
|
|
6
6
|
if (dir) {
|
|
7
7
|
try {
|
|
8
|
-
fs.accessSync(cwd
|
|
8
|
+
fs.accessSync(`${cwd}/${dir}`, fs.F_OK, {
|
|
9
9
|
recursive: true
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
12
|
catch (e) {
|
|
13
|
-
fs.mkdirSync(cwd
|
|
13
|
+
fs.mkdirSync(`${cwd}/${dir}`, {
|
|
14
14
|
recursive: true
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
if (values) {
|
|
19
|
+
const directory = `${cwd}/${dir}/dump-schema_${+new Date()}.sql`;
|
|
20
|
+
new lib_1.DB().backupSchemaToFile({
|
|
21
|
+
filePath: directory,
|
|
22
|
+
database: db
|
|
23
|
+
})
|
|
24
|
+
.then(r => console.log(`dump schema database "${db}" file successfully`))
|
|
25
|
+
.catch(err => console.log(err))
|
|
26
|
+
.finally(() => process.exit(0));
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const directory = `${cwd}/${dir}/dump_${+new Date()}.sql`;
|
|
30
|
+
new lib_1.DB().backupToFile({
|
|
31
|
+
filePath: directory,
|
|
32
|
+
database: db
|
|
33
|
+
})
|
|
34
|
+
.then(r => console.log(`dump database "${db}" file successfully`))
|
|
35
|
+
.catch(err => console.log(err))
|
|
36
|
+
.finally(() => process.exit(0));
|
|
37
|
+
}
|
|
25
38
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
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, values, table } = 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
|
+
if (values) {
|
|
19
|
+
const directory = `${cwd}/${dir}/dump-schema_${+new Date()}.sql`;
|
|
20
|
+
new lib_1.DB().backupTableSchemaToFile({
|
|
21
|
+
filePath: directory,
|
|
22
|
+
table
|
|
23
|
+
})
|
|
24
|
+
.then(r => console.log(`dump table schema "${table}" file successfully`))
|
|
25
|
+
.catch(err => console.log(err))
|
|
26
|
+
.finally(() => process.exit(0));
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const directory = `${cwd}/${dir}/dump_${+new Date()}.sql`;
|
|
30
|
+
new lib_1.DB().backupTableToFile({
|
|
31
|
+
filePath: directory,
|
|
32
|
+
table
|
|
33
|
+
})
|
|
34
|
+
.then(r => console.log(`dump table "${table}" file successfully`))
|
|
35
|
+
.catch(err => console.log(err))
|
|
36
|
+
.finally(() => process.exit(0));
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -10,12 +10,12 @@ exports.default = (cmd) => {
|
|
|
10
10
|
const { dir, cwd, type, fs, npm } = cmd;
|
|
11
11
|
if (dir) {
|
|
12
12
|
try {
|
|
13
|
-
fs.accessSync(cwd
|
|
13
|
+
fs.accessSync(`${cwd}/${dir}`, fs.F_OK, {
|
|
14
14
|
recursive: true
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
catch (e) {
|
|
18
|
-
fs.mkdirSync(cwd
|
|
18
|
+
fs.mkdirSync(`${cwd}/${dir}`, {
|
|
19
19
|
recursive: true
|
|
20
20
|
});
|
|
21
21
|
}
|
|
@@ -27,19 +27,36 @@ exports.default = (cmd) => {
|
|
|
27
27
|
}
|
|
28
28
|
return str.join('');
|
|
29
29
|
};
|
|
30
|
-
new lib_1.DB().rawQuery('SHOW TABLES')
|
|
30
|
+
new lib_1.DB().rawQuery('SHOW TABLES')
|
|
31
|
+
.then(tables => {
|
|
31
32
|
var _a;
|
|
32
33
|
for (let i = 0; i < tables.length; i++) {
|
|
33
34
|
const table = String((_a = Object.values(tables[i])) === null || _a === void 0 ? void 0 : _a.shift());
|
|
34
35
|
const model = snakeCaseToPascal(pluralize_1.default.singular(table));
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
new lib_1.DB().rawQuery(`SHOW COLUMNS FROM ${table}`).then(raw => {
|
|
37
|
+
let schema = '';
|
|
38
|
+
for (const r of raw) {
|
|
39
|
+
schema += `${r.Field} : `;
|
|
40
|
+
schema += `new Blueprint().${/^[^()]*$/.test(r.Type) ? `${r.Type.toLocaleLowerCase()}()` : r.Type.toLocaleLowerCase()}`;
|
|
41
|
+
schema += `${r.Null === 'YES' ? '.null()' : '.notNull()'}`;
|
|
42
|
+
schema += r.Key === 'PRI' ? '.primary()' : r.Key === 'UNI' ? '.unique()' : '';
|
|
43
|
+
schema += r.Default != null ? `.default('${r.Default}')` : '';
|
|
44
|
+
schema += `${r.Extra === 'auto_increment' ? '.autoIncrement()' : ''},
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
47
|
+
const data = (0, model_1.default)(model, npm, `this.useSchema({
|
|
48
|
+
${schema.replace(/,\s*$/, "")}
|
|
49
|
+
})`);
|
|
50
|
+
fs.writeFile(`${cwd}/${dir}/${model}${type !== null && type !== void 0 ? type : '.ts'}`, data, (err) => {
|
|
51
|
+
if (err)
|
|
52
|
+
throw err;
|
|
53
|
+
});
|
|
54
|
+
console.log(`Model : '${model}' created successfully`);
|
|
55
|
+
})
|
|
56
|
+
.catch(err => console.log(err));
|
|
41
57
|
}
|
|
42
58
|
console.log('\nGenerate Models has completed');
|
|
43
59
|
})
|
|
44
|
-
.catch(err => console.log(err))
|
|
60
|
+
.catch(err => console.log(err))
|
|
61
|
+
.finally(() => process.exit(0));
|
|
45
62
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const Model: (model: string, npm: string) => string;
|
|
1
|
+
declare const Model: (model: string, npm: string, schema: string) => string;
|
|
2
2
|
export default Model;
|
|
@@ -1,26 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const Model = (model, npm) => {
|
|
4
|
-
return `import { Model } from '${npm}'
|
|
3
|
+
const Model = (model, npm, schema) => {
|
|
4
|
+
return `import { Model , Blueprint } from '${npm}'
|
|
5
5
|
class ${model} extends Model {
|
|
6
6
|
constructor(){
|
|
7
7
|
super()
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* this.
|
|
13
|
-
* this.
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* this.
|
|
18
|
-
* this.
|
|
19
|
-
* this.
|
|
20
|
-
* this.
|
|
21
|
-
* this.
|
|
22
|
-
* this.
|
|
23
|
-
|
|
10
|
+
* @Configuration registry in your model
|
|
11
|
+
*
|
|
12
|
+
* this.useDebug()
|
|
13
|
+
* this.useTimestamp({
|
|
14
|
+
* createdAt : 'created_at',
|
|
15
|
+
* updatedAt : 'updated_at'
|
|
16
|
+
* }) // runing a timestamp when insert or update
|
|
17
|
+
* this.useSoftDelete('deletedAt') // => default target to colmun deleted_at
|
|
18
|
+
* this.usePattern('snake_case') // => default 'snake_case'
|
|
19
|
+
* this.useUUID('uuid') // => runing a uuid (universally unique identifier) when insert new data
|
|
20
|
+
* this.useRegistry() // => build-in functions registry
|
|
21
|
+
* this.useLoadRelationsInRegistry() // => auto generated results from relationship to results
|
|
22
|
+
* this.useBuiltInRelationFunctions() // => build-in functions relationships to results
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @Schema table
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
${schema}
|
|
24
31
|
}
|
|
25
32
|
}
|
|
26
33
|
export { ${model} }
|
package/dist/cli/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const make_1 = __importDefault(require("./models/make"));
|
|
@@ -12,6 +12,7 @@ const make_3 = __importDefault(require("./migrate/make"));
|
|
|
12
12
|
const make_4 = __importDefault(require("./generate/make"));
|
|
13
13
|
const query_1 = __importDefault(require("./query"));
|
|
14
14
|
const db_1 = __importDefault(require("./dump/db"));
|
|
15
|
+
const db_2 = __importDefault(require("./dump/db"));
|
|
15
16
|
const commands = {
|
|
16
17
|
'query': query_1.default,
|
|
17
18
|
'make:model': make_1.default,
|
|
@@ -19,7 +20,9 @@ const commands = {
|
|
|
19
20
|
'make:migration': make_2.default,
|
|
20
21
|
'migrate': make_3.default,
|
|
21
22
|
'generate:models': make_4.default,
|
|
23
|
+
'gen:models': make_4.default,
|
|
22
24
|
'dump:db': db_1.default,
|
|
25
|
+
'dump:table': db_2.default
|
|
23
26
|
};
|
|
24
27
|
try {
|
|
25
28
|
const name = (_c = (_b = (_a = process.argv.slice(2)) === null || _a === void 0 ? void 0 : _a.find(data => {
|
|
@@ -33,11 +36,20 @@ try {
|
|
|
33
36
|
const db = (_m = (_l = (_k = process.argv.slice(2)) === null || _k === void 0 ? void 0 : _k.find(data => {
|
|
34
37
|
return data === null || data === void 0 ? void 0 : data.includes('--db=');
|
|
35
38
|
})) === null || _l === void 0 ? void 0 : _l.replace('--db=', '')) !== null && _m !== void 0 ? _m : null;
|
|
36
|
-
|
|
39
|
+
const table = (_q = (_p = (_o = process.argv.slice(2)) === null || _o === void 0 ? void 0 : _o.find(data => {
|
|
40
|
+
return data === null || data === void 0 ? void 0 : data.includes('--table=');
|
|
41
|
+
})) === null || _p === void 0 ? void 0 : _p.replace('--table=', '')) !== null && _q !== void 0 ? _q : null;
|
|
42
|
+
let type = ((_t = (_s = (_r = process.argv.slice(2)) === null || _r === void 0 ? void 0 : _r.find(data => {
|
|
37
43
|
return data === null || data === void 0 ? void 0 : data.includes('--type=');
|
|
38
|
-
})) === null ||
|
|
44
|
+
})) === null || _s === void 0 ? void 0 : _s.replace('--type=', '.')) !== null && _t !== void 0 ? _t : '.ts');
|
|
39
45
|
type = ['.js', '.ts'].includes(type) ? type : '.ts';
|
|
40
|
-
const file = (
|
|
46
|
+
const file = (_u = process.argv.slice(3)[0]) !== null && _u !== void 0 ? _u : '';
|
|
47
|
+
const env = (_x = (_w = (_v = process.argv.slice(2)) === null || _v === void 0 ? void 0 : _v.find(data => {
|
|
48
|
+
return data === null || data === void 0 ? void 0 : data.includes('--env=');
|
|
49
|
+
})) === null || _w === void 0 ? void 0 : _w.replace('--env=', '')) !== null && _x !== void 0 ? _x : null;
|
|
50
|
+
const values = (_0 = (((_y = process.argv.slice(2)) === null || _y === void 0 ? void 0 : _y.includes('--values')) || ((_z = process.argv.slice(2)) === null || _z === void 0 ? void 0 : _z.includes('--v')))) !== null && _0 !== void 0 ? _0 : false;
|
|
51
|
+
if (env != null)
|
|
52
|
+
process.env.NODE_ENV = env;
|
|
41
53
|
const cmd = {
|
|
42
54
|
name,
|
|
43
55
|
file,
|
|
@@ -48,6 +60,8 @@ try {
|
|
|
48
60
|
fs: fs_1.default,
|
|
49
61
|
sql,
|
|
50
62
|
db,
|
|
63
|
+
table,
|
|
64
|
+
values,
|
|
51
65
|
npm: 'tspace-mysql'
|
|
52
66
|
};
|
|
53
67
|
commands[process.argv[2]](cmd);
|
|
@@ -59,7 +73,9 @@ catch (err) {
|
|
|
59
73
|
tspace-mysql migrate --dir=App/Models/Migrations --type=js
|
|
60
74
|
tspace-mysql query "SELECT * FROM users"
|
|
61
75
|
tspace-mysql generate:models --dir=app/Models
|
|
62
|
-
tspace-mysql dump:db --dir=app/
|
|
76
|
+
tspace-mysql dump:db --db=database --dir=app/db
|
|
77
|
+
tspace-mysql dump:table --table=table --dir=app/table
|
|
63
78
|
`);
|
|
64
79
|
console.log(`Read more https://www.npmjs.com/package/tspace-mysql`);
|
|
80
|
+
process.exit(0);
|
|
65
81
|
}
|
package/dist/cli/migrate/make.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const child_process_1 = require("child_process");
|
|
4
|
-
exports.default = (
|
|
4
|
+
exports.default = (commandInput) => {
|
|
5
5
|
var _a, _b, _c;
|
|
6
|
-
const { type, dir, cwd, fs } =
|
|
6
|
+
const { type, dir, cwd, fs } = commandInput;
|
|
7
7
|
try {
|
|
8
8
|
if (dir == null)
|
|
9
9
|
throw new Error('Not found directory');
|
package/dist/cli/models/make.js
CHANGED
|
@@ -10,12 +10,12 @@ exports.default = (cmd) => {
|
|
|
10
10
|
const { file, migrate, dir, type, cwd, fs, npm } = cmd;
|
|
11
11
|
if (dir) {
|
|
12
12
|
try {
|
|
13
|
-
fs.accessSync(cwd
|
|
13
|
+
fs.accessSync(`${cwd}/${dir}`, fs.F_OK, {
|
|
14
14
|
recursive: true
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
catch (e) {
|
|
18
|
-
fs.mkdirSync(cwd
|
|
18
|
+
fs.mkdirSync(`${cwd}/${dir}`, {
|
|
19
19
|
recursive: true
|
|
20
20
|
});
|
|
21
21
|
}
|
package/dist/cli/models/model.js
CHANGED
|
@@ -7,7 +7,7 @@ class ${model} extends Model {
|
|
|
7
7
|
super()
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
10
|
-
* Assign setting global in your model
|
|
10
|
+
* //Assign setting global in your model
|
|
11
11
|
* @useMethod
|
|
12
12
|
*
|
|
13
13
|
* this.useDebug()
|
|
@@ -16,19 +16,6 @@ class ${model} extends Model {
|
|
|
16
16
|
* createdAt : 'created_at',
|
|
17
17
|
* updatedAt : 'updated_at'
|
|
18
18
|
* }) // runing a timestamp when insert or update
|
|
19
|
-
* this.useSoftDelete()
|
|
20
|
-
* this.useTable('users')
|
|
21
|
-
* this.useTableSingular() // 'user'
|
|
22
|
-
* this.useTablePlural() // 'users'
|
|
23
|
-
* this.usePattern('snake_case') // by defalut snake_case
|
|
24
|
-
* this.useUUID('uuid') // => runing a uuid (universally unique identifier) when insert new data
|
|
25
|
-
* this.useRegistry()
|
|
26
|
-
* this.useSchema({
|
|
27
|
-
* id : Number,
|
|
28
|
-
* username : String
|
|
29
|
-
* created_at : Date,
|
|
30
|
-
* updated_at : Date,
|
|
31
|
-
* }) // validate type of schema when return result
|
|
32
19
|
*/
|
|
33
20
|
}
|
|
34
21
|
}
|
package/dist/cli/query/index.js
CHANGED
|
@@ -3,5 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const lib_1 = require("../../lib");
|
|
4
4
|
exports.default = (cmd) => {
|
|
5
5
|
const { sql } = cmd;
|
|
6
|
-
new lib_1.DB().rawQuery(sql === null || sql === void 0 ? void 0 : sql.replace(/`/g, ''))
|
|
6
|
+
new lib_1.DB().rawQuery(sql === null || sql === void 0 ? void 0 : sql.replace(/`/g, ''))
|
|
7
|
+
.then(result => console.log(result))
|
|
8
|
+
.catch(err => console.log(err))
|
|
9
|
+
.finally(() => process.exit(0));
|
|
7
10
|
};
|
|
@@ -18,22 +18,23 @@ const environment = () => {
|
|
|
18
18
|
return env;
|
|
19
19
|
};
|
|
20
20
|
dotenv_1.default.config({ path: environment() });
|
|
21
|
+
const ENV = process.env;
|
|
21
22
|
const env = {
|
|
22
|
-
HOST:
|
|
23
|
-
PORT:
|
|
24
|
-
USERNAME:
|
|
25
|
-
PASSWORD:
|
|
26
|
-
DATABASE:
|
|
27
|
-
CONNECTION_LIMIT:
|
|
28
|
-
QUEUE_LIMIT:
|
|
29
|
-
TIMEOUT:
|
|
30
|
-
CHARSET:
|
|
31
|
-
CONNECTION_ERROR:
|
|
32
|
-
WAIT_FOR_CONNECTIONS:
|
|
33
|
-
DATE_STRINGS:
|
|
34
|
-
KEEP_ALIVE_DELAY:
|
|
35
|
-
ENABLE_KEEP_ALIVE:
|
|
36
|
-
MULTIPLE_STATEMENTS:
|
|
23
|
+
HOST: ENV.DB_HOST || ENV.TSPACE_HOST,
|
|
24
|
+
PORT: ENV.DB_PORT || ENV.TSPACE_PORT || 3306,
|
|
25
|
+
USERNAME: ENV.DB_USERNAME || ENV.TSPACE_USERNAME,
|
|
26
|
+
PASSWORD: ENV.DB_PASSWORD || ENV.TSPACE_PASSWORD || '',
|
|
27
|
+
DATABASE: ENV.DB_DATABASE || ENV.TSPACE_DATABASE,
|
|
28
|
+
CONNECTION_LIMIT: ENV.DB_CONNECTION_LIMIT || ENV.TSPACE_CONNECTION_LIMIT || 30,
|
|
29
|
+
QUEUE_LIMIT: ENV.DB_QUEUE_LIMIT || ENV.TSPACE_QUEUE_LIMIT || 0,
|
|
30
|
+
TIMEOUT: ENV.DB_TIMEOUT || ENV.TSPACE_TIMEOUT || 1000 * 60,
|
|
31
|
+
CHARSET: ENV.DB_CHARSET || ENV.TSPACE_CHARSET || 'utf8mb4',
|
|
32
|
+
CONNECTION_ERROR: ENV.DB_CONNECTION_ERROR || ENV.TSPACE_CONNECTION_ERROR || true,
|
|
33
|
+
WAIT_FOR_CONNECTIONS: ENV.DB_WAIT_FOR_CONNECTIONS || ENV.TSPACE_WAIT_FOR_CONNECTIONS || true,
|
|
34
|
+
DATE_STRINGS: ENV.DB_DATE_STRINGS || ENV.TSPACE_DATE_STRINGS || true,
|
|
35
|
+
KEEP_ALIVE_DELAY: ENV.DB_KEEP_ALIVE_DELAY || ENV.TSPACE_KEEP_ALIVE_DELAY || 0,
|
|
36
|
+
ENABLE_KEEP_ALIVE: ENV.DB_ENABLE_KEEP_ALIVE || ENV.TSPACE_ENABLE_KEEP_ALIVE || false,
|
|
37
|
+
MULTIPLE_STATEMENTS: ENV.MULTIPLE_STATEMENTS || ENV.TSPACE_MULTIPLE_STATEMENTS || false
|
|
37
38
|
};
|
|
38
39
|
for (const [key, value] of Object.entries(env)) {
|
|
39
40
|
if (value == null)
|
|
@@ -67,6 +67,9 @@ const CONSTANTS = Object.freeze({
|
|
|
67
67
|
CREATE_TABLE_NOT_EXISTS: 'CREATE TABLE IF NOT EXISTS',
|
|
68
68
|
ENGINE: 'ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8',
|
|
69
69
|
RAND: 'RAND()',
|
|
70
|
+
ALTER_TABLE: 'ALTER TABLE',
|
|
71
|
+
ADD: 'ADD',
|
|
72
|
+
AFTER: 'AFTER',
|
|
70
73
|
RELATIONSHIP: {
|
|
71
74
|
hasOne: 'hasOne',
|
|
72
75
|
hasMany: 'hasMany',
|
|
@@ -159,9 +162,10 @@ const CONSTANTS = Object.freeze({
|
|
|
159
162
|
CREATED_AT: 'created_at',
|
|
160
163
|
UPDATED_AT: 'updated_at'
|
|
161
164
|
},
|
|
162
|
-
|
|
165
|
+
VALIDATE_SCHEMA: false,
|
|
166
|
+
VALIDATE_SCHEMA_DEFINED: null,
|
|
163
167
|
FUNCTION_RELATION: false,
|
|
164
|
-
|
|
168
|
+
SCHEMA_TABLE: null,
|
|
165
169
|
QUERIES: 0
|
|
166
170
|
}
|
|
167
171
|
});
|
|
@@ -14,7 +14,7 @@ declare abstract class AbstractDB extends Builder {
|
|
|
14
14
|
when: string;
|
|
15
15
|
then: string;
|
|
16
16
|
}[], final?: string): string | [];
|
|
17
|
-
abstract getConnection(options: ConnectionOptions): Connection
|
|
17
|
+
abstract getConnection(options: ConnectionOptions): Promise<Connection>;
|
|
18
18
|
}
|
|
19
19
|
export { AbstractDB };
|
|
20
20
|
export default AbstractDB;
|