tspace-mysql 1.1.4 → 1.1.6
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 +73 -37
- package/dist/cli/index.js +23 -24
- package/dist/cli/migrate/make.js +18 -41
- package/dist/cli/models/make.js +18 -18
- package/dist/cli/models/model.js +27 -2
- package/dist/cli/tables/make.js +10 -10
- package/dist/cli/tables/table.js +22 -2
- package/dist/lib/config/env.d.ts +4 -5
- package/dist/lib/config/env.js +12 -14
- package/dist/lib/connection/index.js +78 -70
- package/dist/lib/constants/index.d.ts +4 -0
- package/dist/lib/constants/index.js +7 -4
- package/dist/lib/index.js +1 -1
- package/dist/lib/tspace/AbstractDB.js +3 -23
- package/dist/lib/tspace/AbstractDatabase.js +28 -31
- package/dist/lib/tspace/AbstractModel.js +3 -23
- package/dist/lib/tspace/Blueprint.js +79 -119
- package/dist/lib/tspace/DB.d.ts +36 -6
- package/dist/lib/tspace/DB.js +113 -216
- package/dist/lib/tspace/Database.d.ts +11 -1
- package/dist/lib/tspace/Database.js +1236 -1978
- package/dist/lib/tspace/Logger.js +17 -18
- package/dist/lib/tspace/Model.d.ts +13 -8
- package/dist/lib/tspace/Model.js +1292 -2065
- package/dist/lib/tspace/ProxyHandler.js +15 -26
- package/dist/lib/tspace/Schema.js +25 -117
- package/dist/lib/tspace/index.js +4 -4
- package/dist/lib/utils/index.js +69 -106
- package/package.json +3 -3
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
|
|
@@ -24,7 +24,7 @@ npm install tspace-mysql --save
|
|
|
24
24
|
- [Relationships](#relationships)
|
|
25
25
|
- [One To One](#one-to-one)
|
|
26
26
|
- [One To Many](#one-to-many)
|
|
27
|
-
- [
|
|
27
|
+
- [Belongs To](#belongs-to)
|
|
28
28
|
- [Many To Many](#many-to-many)
|
|
29
29
|
- [Query Builder](#query-builder)
|
|
30
30
|
- [Cli](#cli)
|
|
@@ -207,7 +207,7 @@ Backup database, you may backup is this:
|
|
|
207
207
|
* @param conection defalut current connection
|
|
208
208
|
*/
|
|
209
209
|
const backup = await new DB().backup({
|
|
210
|
-
database: 'try-to-backup',
|
|
210
|
+
database: 'try-to-backup', // clone current database to this
|
|
211
211
|
connection ?: {
|
|
212
212
|
host: 'localhost',
|
|
213
213
|
port : 3306,
|
|
@@ -240,9 +240,18 @@ const backupToFile = await new DB().backupToFile({
|
|
|
240
240
|
To get started, let's install npm install tspace-mysql -g
|
|
241
241
|
you may use the make:model command to generate a new model:
|
|
242
242
|
|
|
243
|
-
```
|
|
243
|
+
```js
|
|
244
|
+
/**
|
|
245
|
+
*
|
|
246
|
+
* @install global command
|
|
247
|
+
*/
|
|
244
248
|
npm install tspace-mysql -g
|
|
245
|
-
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
*
|
|
252
|
+
* @make Model
|
|
253
|
+
*/
|
|
254
|
+
tspace-mysql make:model <model name> --dir=< directory >
|
|
246
255
|
|
|
247
256
|
# tspace-mysql make:model User --dir=App/Models
|
|
248
257
|
# => App/Models/User.ts
|
|
@@ -346,7 +355,8 @@ const postsUsingFunction = await new Post().comments().findOne()
|
|
|
346
355
|
// postsUsingFunction?.comments => [{...}]
|
|
347
356
|
```
|
|
348
357
|
|
|
349
|
-
##
|
|
358
|
+
## Belongs To
|
|
359
|
+
A belongsto relationship is used to define relationships where a single model is the child to parent models.
|
|
350
360
|
```js
|
|
351
361
|
import { Model } from 'tspace-mysql'
|
|
352
362
|
import User from '../User'
|
|
@@ -419,7 +429,7 @@ const userUsingFunction = await new User().roles().findOne()
|
|
|
419
429
|
// user?.roles => [{...}]
|
|
420
430
|
```
|
|
421
431
|
## Query Builder
|
|
422
|
-
|
|
432
|
+
Methods builder for queries
|
|
423
433
|
```js
|
|
424
434
|
where(column , operator , value)
|
|
425
435
|
whereSensitive(column , operator , value)
|
|
@@ -468,17 +478,17 @@ belongsToMany({ name , model , localKey , foreignKey , freezeTable , as })
|
|
|
468
478
|
*/
|
|
469
479
|
relations(name1 , name2,...nameN)
|
|
470
480
|
/**
|
|
471
|
-
* @relation using registry in your models. if exists child data remove this
|
|
481
|
+
* @relation using registry in your models. if exists child data remove this data
|
|
472
482
|
*/
|
|
473
483
|
relationsExists(name1 , name2,...nameN)
|
|
474
484
|
/**
|
|
475
|
-
* @relation call a relation in registry, callback query of
|
|
485
|
+
* @relation call a name of relation in registry, callback query of data
|
|
476
486
|
*/
|
|
477
|
-
relationQuery(name,(callback))
|
|
487
|
+
relationQuery(name, (callback) )
|
|
478
488
|
|
|
479
489
|
/**
|
|
480
490
|
* queries statements
|
|
481
|
-
* @execute data statements
|
|
491
|
+
* @execute data of statements
|
|
482
492
|
*/
|
|
483
493
|
findMany()
|
|
484
494
|
findOne()
|
|
@@ -505,54 +515,79 @@ you may use a basic cli :
|
|
|
505
515
|
|
|
506
516
|
## Make Model
|
|
507
517
|
Command will be placed Model in the specific directory
|
|
508
|
-
```
|
|
509
|
-
|
|
518
|
+
```js
|
|
519
|
+
|
|
510
520
|
/**
|
|
521
|
+
*
|
|
522
|
+
* @make Model
|
|
511
523
|
* @options
|
|
512
|
-
* --m
|
|
513
|
-
* --dir=directory
|
|
514
|
-
* --type=js // extension js default ts
|
|
524
|
+
* @arg --m => created scheme table for migrate. short cut migration table like Make Migration
|
|
525
|
+
* @arg --dir=directory => created model in directory. default root directory
|
|
526
|
+
* @arg --type=js // extension js. default ts
|
|
515
527
|
*/
|
|
528
|
+
tspace-mysql make:model <model name> --m --dir=.... --type=....
|
|
516
529
|
|
|
517
530
|
tspace-mysql make:model User --m --dir=app/Models
|
|
518
|
-
|
|
531
|
+
/**
|
|
532
|
+
*
|
|
533
|
+
* @Ex directory
|
|
534
|
+
*/
|
|
519
535
|
- node_modules
|
|
520
536
|
- app
|
|
521
537
|
- Models
|
|
522
538
|
User.ts
|
|
523
|
-
*/
|
|
524
539
|
```
|
|
525
540
|
|
|
526
541
|
## Make Migration
|
|
527
542
|
Command will be placed Migration in the specific directory
|
|
528
|
-
```
|
|
529
|
-
|
|
530
|
-
|
|
543
|
+
```js
|
|
544
|
+
/**
|
|
545
|
+
*
|
|
546
|
+
* @make Migration Table
|
|
531
547
|
* @options
|
|
532
|
-
* --
|
|
533
|
-
* --
|
|
548
|
+
* @arg --dir=directory => created scheme table in directory. default root directory
|
|
549
|
+
* @arg --type=js // extension js default ts
|
|
534
550
|
*/
|
|
551
|
+
tspace-mysql make:migration <table name> --type=... --dir=....
|
|
552
|
+
|
|
535
553
|
tspace-mysql make:migration users --dir=app/Models/Migrations
|
|
536
|
-
|
|
554
|
+
/**
|
|
555
|
+
*
|
|
556
|
+
* @Ex directory
|
|
557
|
+
*/
|
|
537
558
|
- node_modules
|
|
538
559
|
- app
|
|
539
560
|
- Models
|
|
540
561
|
- Migrations
|
|
541
562
|
create_users_table.ts
|
|
542
563
|
User.ts
|
|
543
|
-
*/
|
|
544
564
|
```
|
|
545
565
|
## Migrate
|
|
546
|
-
```
|
|
547
|
-
|
|
548
|
-
|
|
566
|
+
```js
|
|
567
|
+
/**
|
|
568
|
+
*
|
|
569
|
+
* @run Migrate table
|
|
549
570
|
* @options
|
|
550
|
-
|
|
551
|
-
|
|
571
|
+
* @arg --dir=directory => find migrate in directory. default find in root folder
|
|
572
|
+
* @arg --type=js // extension js default ts
|
|
552
573
|
*/
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
574
|
+
tspace-mysql migrate <folder> --type=... --dir=....
|
|
575
|
+
|
|
576
|
+
tspace-mysql migrate --dir=App/Models/Migrations --type=js
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
*
|
|
580
|
+
* @Ex directory
|
|
581
|
+
*/
|
|
582
|
+
- node_modules
|
|
583
|
+
- app
|
|
584
|
+
- Models
|
|
585
|
+
- Migrations
|
|
586
|
+
create_users_table.ts
|
|
587
|
+
create_posts_table.ts
|
|
588
|
+
User.ts
|
|
589
|
+
Post.ts
|
|
590
|
+
// => migrate all schemas in folder <Migrations>. created into database
|
|
556
591
|
```
|
|
557
592
|
|
|
558
593
|
## Blueprint
|
|
@@ -562,8 +597,9 @@ import { Schema , Blueprint , DB } from 'tspace-mysql'
|
|
|
562
597
|
(async () => {
|
|
563
598
|
await new Schema().table('users',{
|
|
564
599
|
id : new Blueprint().int().notNull().primary().autoIncrement(),
|
|
565
|
-
|
|
566
|
-
|
|
600
|
+
uuid : new Blueprint().varchar(120).null()
|
|
601
|
+
name : new Blueprint().varchar(120).default('name'),
|
|
602
|
+
email : new Blueprint().varchar(255).unique().notNull(),
|
|
567
603
|
email_verify : new Blueprint().tinyInt(),
|
|
568
604
|
password : new Blueprint().varchar(255),
|
|
569
605
|
created_at : new Blueprint().null().timestamp(),
|
|
@@ -577,7 +613,7 @@ import { Schema , Blueprint , DB } from 'tspace-mysql'
|
|
|
577
613
|
})()
|
|
578
614
|
|
|
579
615
|
/**
|
|
580
|
-
*
|
|
616
|
+
* type of schema in database
|
|
581
617
|
* @Types
|
|
582
618
|
*
|
|
583
619
|
*/
|
|
@@ -598,7 +634,7 @@ dateTime()
|
|
|
598
634
|
timestamp ()
|
|
599
635
|
|
|
600
636
|
/**
|
|
601
|
-
*
|
|
637
|
+
* attrbuites of schema in database
|
|
602
638
|
* @Attrbuites
|
|
603
639
|
*
|
|
604
640
|
*/
|
package/dist/cli/index.js
CHANGED
|
@@ -3,37 +3,36 @@
|
|
|
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;
|
|
7
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const make_1 = __importDefault(require("./models/make"));
|
|
9
|
+
const make_2 = __importDefault(require("./tables/make"));
|
|
10
|
+
const make_3 = __importDefault(require("./migrate/make"));
|
|
11
|
+
const commands = {
|
|
13
12
|
'make:model': make_1.default,
|
|
14
13
|
'make:table': make_2.default,
|
|
15
14
|
'make:migration': make_2.default,
|
|
16
15
|
'migrate': make_3.default
|
|
17
16
|
};
|
|
18
17
|
try {
|
|
19
|
-
|
|
20
|
-
return data
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return data
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
return data
|
|
28
|
-
})
|
|
18
|
+
const name = process.argv.slice(2)?.find(data => {
|
|
19
|
+
return data?.includes('--name=');
|
|
20
|
+
})?.replace('--name=', '') ?? null;
|
|
21
|
+
const migrate = process.argv.slice(2)?.includes('--m') ?? false;
|
|
22
|
+
const dir = process.argv.slice(2)?.find(data => {
|
|
23
|
+
return data?.includes('--dir=');
|
|
24
|
+
})?.replace('--dir=', '/') ?? null;
|
|
25
|
+
let type = process.argv.slice(2)?.find(data => {
|
|
26
|
+
return data?.includes('--type=');
|
|
27
|
+
})?.replace('--type=', '.') ?? '.ts';
|
|
29
28
|
type = ['.js', '.ts'].includes(type) ? type : '.ts';
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
name
|
|
33
|
-
file
|
|
34
|
-
dir
|
|
35
|
-
migrate
|
|
36
|
-
type
|
|
29
|
+
const file = process.argv.slice(3)?.shift() ?? '';
|
|
30
|
+
const cmd = {
|
|
31
|
+
name,
|
|
32
|
+
file,
|
|
33
|
+
dir,
|
|
34
|
+
migrate,
|
|
35
|
+
type,
|
|
37
36
|
cwd: process.cwd(),
|
|
38
37
|
fs: fs_1.default,
|
|
39
38
|
npm: 'tspace-mysql'
|
|
@@ -41,5 +40,5 @@ try {
|
|
|
41
40
|
commands[process.argv[2]](cmd);
|
|
42
41
|
}
|
|
43
42
|
catch (err) {
|
|
44
|
-
console.log(
|
|
43
|
+
console.log(`readme https://www.npmjs.com/package/tspace-mysql`);
|
|
45
44
|
}
|
package/dist/cli/migrate/make.js
CHANGED
|
@@ -1,52 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function(o) {
|
|
3
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
-
if (m) return m.call(o);
|
|
5
|
-
if (o && typeof o.length === "number") return {
|
|
6
|
-
next: function () {
|
|
7
|
-
if (o && i >= o.length) o = void 0;
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
|
|
15
|
-
exports.default = (
|
|
16
|
-
|
|
17
|
-
var _b, _c, _d;
|
|
18
|
-
var type = formCommand.type, dir = formCommand.dir, cwd = formCommand.cwd, fs = formCommand.fs;
|
|
3
|
+
const child_process_1 = require("child_process");
|
|
4
|
+
exports.default = (formCommand) => {
|
|
5
|
+
const { type, dir, cwd, fs } = formCommand;
|
|
19
6
|
try {
|
|
20
7
|
if (dir == null)
|
|
21
8
|
throw new Error('Not found directory');
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!
|
|
9
|
+
const path = `${cwd}/${dir}`;
|
|
10
|
+
const files = fs.readdirSync(path) ?? [];
|
|
11
|
+
if (!files?.length)
|
|
25
12
|
console.log('this folder is empty');
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
console.error(err);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
42
|
-
finally {
|
|
43
|
-
try {
|
|
44
|
-
if (files_1_1 && !files_1_1.done && (_a = files_1.return)) _a.call(files_1);
|
|
45
|
-
}
|
|
46
|
-
finally { if (e_1) throw e_1.error; }
|
|
13
|
+
const cmd = type === '.js' ? 'node' : 'ts-node';
|
|
14
|
+
for (const _file of files) {
|
|
15
|
+
const run = (0, child_process_1.exec)(`${cmd} ${path}/${_file}`);
|
|
16
|
+
run?.stdout?.on('data', (data) => {
|
|
17
|
+
if (data)
|
|
18
|
+
console.log(data);
|
|
19
|
+
});
|
|
20
|
+
run?.stderr?.on('data', (err) => {
|
|
21
|
+
if (err)
|
|
22
|
+
console.error(err);
|
|
23
|
+
});
|
|
47
24
|
}
|
|
48
25
|
}
|
|
49
26
|
catch (err) {
|
|
50
27
|
console.log(err.message);
|
|
51
28
|
}
|
|
52
|
-
}
|
|
29
|
+
};
|
package/dist/cli/models/make.js
CHANGED
|
@@ -3,33 +3,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.default = (
|
|
10
|
-
|
|
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 = (formCommand) => {
|
|
10
|
+
const { file, migrate, dir, type, cwd, fs, npm } = formCommand;
|
|
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
|
}
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
fs.writeFile(model, data,
|
|
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
26
|
if (err)
|
|
27
27
|
throw err.message;
|
|
28
28
|
});
|
|
29
|
-
console.log(
|
|
29
|
+
console.log(`Model : '${file}' created successfully`);
|
|
30
30
|
if (migrate) {
|
|
31
|
-
|
|
32
|
-
|
|
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
33
|
try {
|
|
34
34
|
fs.accessSync(cwd + folder, fs.F_OK, {
|
|
35
35
|
recursive: true
|
|
@@ -40,12 +40,12 @@ exports.default = (function (formCommand) {
|
|
|
40
40
|
recursive: true
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
fs.writeFile(folderMigrate, table,
|
|
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
46
|
if (err)
|
|
47
47
|
throw err;
|
|
48
48
|
});
|
|
49
|
-
console.log(
|
|
49
|
+
console.log(`Migration : '${tableName}' created successfully`);
|
|
50
50
|
}
|
|
51
|
-
}
|
|
51
|
+
};
|
package/dist/cli/models/model.js
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
return
|
|
3
|
+
const Model = (model, npm) => {
|
|
4
|
+
return `import { Model } from '${npm}'
|
|
5
|
+
class ${model} extends Model {
|
|
6
|
+
constructor(){
|
|
7
|
+
super()
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* Assign setting global in your model
|
|
11
|
+
* @useMethod
|
|
12
|
+
*
|
|
13
|
+
* this.useDebug() // => runing a uuid (universally unique identifier) when insert new data
|
|
14
|
+
* this.usePrimaryKey('id') // => runing a uuid (universally unique identifier) when insert new data
|
|
15
|
+
* this.useTimestamp({ createdAt : 'created_at' , updatedAt : 'updated_at' }) // runing a timestamp when insert or update
|
|
16
|
+
* this.useSoftDelete()
|
|
17
|
+
* this.useDisableSoftDeleteInRelations()
|
|
18
|
+
* this.useTable('Users')
|
|
19
|
+
* this.useTableSingular()
|
|
20
|
+
* this.useTablePlural()
|
|
21
|
+
* this.usePattern('snake_case')
|
|
22
|
+
* this.useUUID('uuid')
|
|
23
|
+
* this.useRegistry()
|
|
24
|
+
*/
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export { ${model} }
|
|
28
|
+
export default ${model}
|
|
29
|
+
`;
|
|
5
30
|
};
|
|
6
31
|
exports.default = Model;
|
package/dist/cli/tables/make.js
CHANGED
|
@@ -3,24 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
exports.default = (
|
|
8
|
-
|
|
6
|
+
const table_1 = __importDefault(require("./table"));
|
|
7
|
+
exports.default = (formCommand) => {
|
|
8
|
+
const { file, type, cwd, dir, fs, npm } = formCommand;
|
|
9
9
|
try {
|
|
10
|
-
fs.accessSync(cwd +
|
|
10
|
+
fs.accessSync(cwd + `/${file}`, fs.F_OK, {
|
|
11
11
|
recursive: true
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
catch (e) {
|
|
15
|
-
fs.mkdirSync(cwd +
|
|
15
|
+
fs.mkdirSync(cwd + `/${file}`, {
|
|
16
16
|
recursive: true
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
fs.writeFile(folderMigrate, table,
|
|
19
|
+
const folderMigrate = dir ? `${cwd}/${dir}/create_${file}_table${type}` : `${cwd}/create_${file}_table${type}`;
|
|
20
|
+
const table = (0, table_1.default)(file, npm);
|
|
21
|
+
fs.writeFile(folderMigrate, table, (err) => {
|
|
22
22
|
if (err)
|
|
23
23
|
console.log(err.message);
|
|
24
24
|
});
|
|
25
|
-
console.log(
|
|
26
|
-
}
|
|
25
|
+
console.log(`Migration : ${file} created successfully`);
|
|
26
|
+
};
|
package/dist/cli/tables/table.js
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
return
|
|
3
|
+
const Table = (table, npm) => {
|
|
4
|
+
return `import { Schema , Blueprint , DB } from '${npm}'
|
|
5
|
+
(async () => {
|
|
6
|
+
await new Schema().table('${table}',{
|
|
7
|
+
id : new Blueprint().int().notNull().primary().autoIncrement(),
|
|
8
|
+
uuid : new Blueprint().varchar(50).null(),
|
|
9
|
+
name : new Blueprint().varchar(120).default('my name'),
|
|
10
|
+
email : new Blueprint().varchar(120).unique(),
|
|
11
|
+
email_verify : new Blueprint().tinyInt(),
|
|
12
|
+
password : new Blueprint().varchar(120),
|
|
13
|
+
birthdate : new Blueprint().date(),
|
|
14
|
+
created_at : new Blueprint().null().timestamp(),
|
|
15
|
+
updated_at : new Blueprint().null().timestamp()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @Faker data
|
|
21
|
+
* await new DB().table('${table}').faker(5)
|
|
22
|
+
*/
|
|
23
|
+
})()
|
|
24
|
+
`;
|
|
5
25
|
};
|
|
6
26
|
exports.default = Table;
|
package/dist/lib/config/env.d.ts
CHANGED
|
@@ -4,11 +4,10 @@ declare const env: Readonly<{
|
|
|
4
4
|
DB_USERNAME: string | undefined;
|
|
5
5
|
DB_PASSWORD: string | undefined;
|
|
6
6
|
DB_DATABASE: string | undefined;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
TSPACE_MYSQL_DATABASE: string | undefined;
|
|
7
|
+
DB_CONNECTION_LIMIT: string | undefined;
|
|
8
|
+
DB_DATE_STRING: string | undefined;
|
|
9
|
+
DB_TIMEOUT: string | undefined;
|
|
10
|
+
DB_QUEUE_LIMIT: string | undefined;
|
|
12
11
|
}>;
|
|
13
12
|
export { env };
|
|
14
13
|
export default env;
|
package/dist/lib/config/env.js
CHANGED
|
@@ -4,14 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.env = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var envWithEnviroment = path_1.default.join(path_1.default.resolve(), ".env.".concat(NODE_ENV));
|
|
7
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const environment = () => {
|
|
11
|
+
const NODE_ENV = process.env?.NODE_ENV;
|
|
12
|
+
const envWithoutEnviroment = path_1.default.join(path_1.default.resolve(), '.env');
|
|
13
|
+
const envWithEnviroment = path_1.default.join(path_1.default.resolve(), `.env.${NODE_ENV}`);
|
|
15
14
|
if (NODE_ENV == null)
|
|
16
15
|
return envWithoutEnviroment;
|
|
17
16
|
if (fs_1.default.existsSync(envWithEnviroment))
|
|
@@ -19,17 +18,16 @@ var environment = function () {
|
|
|
19
18
|
return envWithoutEnviroment;
|
|
20
19
|
};
|
|
21
20
|
dotenv_1.default.config({ path: environment() });
|
|
22
|
-
|
|
21
|
+
const env = Object.freeze({
|
|
23
22
|
DB_HOST: process.env.DB_HOST,
|
|
24
23
|
DB_PORT: process.env.DB_PORT,
|
|
25
24
|
DB_USERNAME: process.env.DB_USERNAME,
|
|
26
25
|
DB_PASSWORD: process.env.DB_PASSWORD,
|
|
27
26
|
DB_DATABASE: process.env.DB_DATABASE,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
TSPACE_MYSQL_DATABASE: process.env.TSPACE_MYSQL_DATABASE
|
|
27
|
+
DB_CONNECTION_LIMIT: process.env.DB_CONNECTION_LIMIT,
|
|
28
|
+
DB_DATE_STRING: process.env.DB_DATE_STRING,
|
|
29
|
+
DB_TIMEOUT: process.env.DB_TIMEOUT,
|
|
30
|
+
DB_QUEUE_LIMIT: process.env.DB_QUEUE_LIMIT
|
|
33
31
|
});
|
|
34
32
|
exports.env = env;
|
|
35
33
|
exports.default = env;
|