tspace-mysql 1.0.2 → 1.0.5
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 +16 -15
- package/dist/cli/index.js +10 -6
- package/dist/cli/migrate/make.d.ts +3 -1
- package/dist/cli/migrate/make.js +12 -9
- package/dist/cli/models/make.d.ts +3 -1
- package/dist/cli/models/make.js +22 -23
- package/dist/cli/tables/make.d.ts +3 -1
- package/dist/cli/tables/make.js +21 -22
- package/dist/cli/tables/table.d.ts +1 -1
- package/dist/cli/tables/table.js +2 -2
- package/dist/lib/connections/options.d.ts +1 -1
- package/dist/lib/{utils/constant.d.ts → constants/index.d.ts} +1 -1
- package/dist/lib/{utils/constant.js → constants/index.js} +0 -2
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/tspace/DB.js +7 -4
- package/dist/lib/tspace/Database.d.ts +4 -0
- package/dist/lib/tspace/Database.js +122 -58
- package/dist/lib/tspace/Interface.d.ts +1 -1
- package/dist/lib/tspace/Logger.js +4 -3
- package/dist/lib/tspace/Model.d.ts +3 -1
- package/dist/lib/tspace/Model.js +139 -136
- package/dist/lib/tspace/Schema.d.ts +3 -2
- package/dist/lib/tspace/Schema.js +0 -2
- package/dist/lib/utils/index.d.ts +1 -1
- package/dist/lib/utils/index.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -142,7 +142,7 @@ Folder directory example
|
|
|
142
142
|
const users = await new User()
|
|
143
143
|
.with('posts','comments') /* relations -> hasMany: posts & comments */
|
|
144
144
|
.withQuery('posts', (query) => query.with('user')) /* relation -> belongsTo: post by user */
|
|
145
|
-
.withQuery('comments', (query) => query.with('user','post')) /* relation -> belongsTo: comment by user? & comment in post
|
|
145
|
+
.withQuery('comments', (query) => query.with('user','post')) /* relation -> belongsTo: comment by user? & comment in post*/
|
|
146
146
|
.findMany()
|
|
147
147
|
|
|
148
148
|
console.log(users)
|
|
@@ -266,25 +266,24 @@ save() /*for action statements insert update or delete */
|
|
|
266
266
|
npm install tspace-mysql -g
|
|
267
267
|
```js
|
|
268
268
|
|
|
269
|
-
tspace-mysql make:model <
|
|
269
|
+
tspace-mysql make:model <MODEL NAME> --m --dir=... --js
|
|
270
270
|
* optional
|
|
271
|
-
--m /* created table for migrate
|
|
272
|
-
--
|
|
273
|
-
--js /* extension
|
|
274
|
-
--name=NAME /* class name default <NAME> in input cli */
|
|
271
|
+
--m /* created table for migrate */
|
|
272
|
+
--dir=directory /* created model in directory */
|
|
273
|
+
--type=js /* extension js default ts */
|
|
275
274
|
|
|
276
|
-
tspace-mysql make:
|
|
277
|
-
* required
|
|
278
|
-
--name=TABLE_NAME /* created table for migrate in <folder> */
|
|
275
|
+
tspace-mysql make:migration <TABLE NAME>
|
|
279
276
|
* optional
|
|
280
|
-
--js /* extension
|
|
277
|
+
--type=js /* extension js default ts */
|
|
278
|
+
--dir=directory /* created table in directory */
|
|
281
279
|
|
|
282
|
-
tspace-mysql migrate <
|
|
280
|
+
tspace-mysql migrate <FOLDER> --js
|
|
283
281
|
* optional
|
|
284
|
-
--js /* extension
|
|
282
|
+
--type=js /* extension js default ts */
|
|
283
|
+
--dir=directory /* find migrate in directory */
|
|
285
284
|
```
|
|
286
285
|
|
|
287
|
-
tspace-mysql make:model
|
|
286
|
+
tspace-mysql make:model User --m --dir=App/Models
|
|
288
287
|
```js
|
|
289
288
|
/* Ex folder
|
|
290
289
|
- node_modules
|
|
@@ -308,7 +307,7 @@ class User extends Model{
|
|
|
308
307
|
}
|
|
309
308
|
export default User
|
|
310
309
|
```
|
|
311
|
-
tspace-mysql make:
|
|
310
|
+
tspace-mysql make:migration users --dir=App/Models/Migrations
|
|
312
311
|
```js
|
|
313
312
|
/* Ex folder
|
|
314
313
|
- node_modules
|
|
@@ -327,6 +326,8 @@ import { Schema , Blueprint , DB } from 'tspace-mysql'
|
|
|
327
326
|
email : new Blueprint().varchar(255).unique(),
|
|
328
327
|
email_verify : new Blueprint().tinyInt(),
|
|
329
328
|
password : new Blueprint().varchar(255),
|
|
329
|
+
created_at : new Blueprint().null().timestamp(),
|
|
330
|
+
updated_at : new Blueprint().null().timestamp()
|
|
330
331
|
})
|
|
331
332
|
/**
|
|
332
333
|
*
|
|
@@ -335,7 +336,7 @@ import { Schema , Blueprint , DB } from 'tspace-mysql'
|
|
|
335
336
|
*/
|
|
336
337
|
})()
|
|
337
338
|
```
|
|
338
|
-
tspace-mysql migrate App/Models
|
|
339
|
+
tspace-mysql migrate Migrations --dir=App/Models
|
|
339
340
|
/* migrate all table in folder into database */
|
|
340
341
|
```js
|
|
341
342
|
* Blueprint method
|
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;
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
var fs_1 = __importDefault(require("fs"));
|
|
9
9
|
var make_1 = __importDefault(require("./models/make"));
|
|
@@ -12,19 +12,23 @@ var make_3 = __importDefault(require("./migrate/make"));
|
|
|
12
12
|
var commands = {
|
|
13
13
|
'make:model': make_1.default,
|
|
14
14
|
'make:table': make_2.default,
|
|
15
|
+
'make:migration': make_2.default,
|
|
15
16
|
'migrate': make_3.default
|
|
16
17
|
};
|
|
17
18
|
try {
|
|
18
19
|
var name = (_c = (_b = (_a = process.argv.slice(2)) === null || _a === void 0 ? void 0 : _a.find(function (data) { return data === null || data === void 0 ? void 0 : data.includes('--name='); })) === null || _b === void 0 ? void 0 : _b.replace('--name=', '')) !== null && _c !== void 0 ? _c : null;
|
|
19
20
|
var migrate = (_e = (_d = process.argv.slice(2)) === null || _d === void 0 ? void 0 : _d.includes('--m')) !== null && _e !== void 0 ? _e : false;
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
var dir = (_h = (_g = (_f = process.argv.slice(2)) === null || _f === void 0 ? void 0 : _f.find(function (data) { return data === null || data === void 0 ? void 0 : data.includes('--dir='); })) === null || _g === void 0 ? void 0 : _g.replace('--dir=', '/')) !== null && _h !== void 0 ? _h : null;
|
|
22
|
+
// const migrateFolder = process.argv.slice(2)?.find(data => data?.includes('--f='))?.replace('--f=','/') ?? null
|
|
23
|
+
// const type = process.argv.slice(2)?.includes('--js') ?? false ? '.js' : '.ts'
|
|
24
|
+
var type = (_l = (_k = (_j = process.argv.slice(2)) === null || _j === void 0 ? void 0 : _j.find(function (data) { return data === null || data === void 0 ? void 0 : data.includes('--type='); })) === null || _k === void 0 ? void 0 : _k.replace('--type=', '.')) !== null && _l !== void 0 ? _l : '.ts';
|
|
25
|
+
type = ['.js', '.ts'].includes(type) ? type : '.ts';
|
|
26
|
+
var file = (_o = (_m = process.argv.slice(3)) === null || _m === void 0 ? void 0 : _m.shift()) !== null && _o !== void 0 ? _o : '';
|
|
23
27
|
var cmd = {
|
|
24
28
|
name: name,
|
|
25
|
-
|
|
29
|
+
file: file,
|
|
30
|
+
dir: dir,
|
|
26
31
|
migrate: migrate,
|
|
27
|
-
migrateFolder: migrateFolder,
|
|
28
32
|
type: type,
|
|
29
33
|
cwd: process.cwd(),
|
|
30
34
|
fs: fs_1.default,
|
package/dist/cli/migrate/make.js
CHANGED
|
@@ -15,29 +15,29 @@ var child_process_1 = require("child_process");
|
|
|
15
15
|
exports.default = (function (_ref) {
|
|
16
16
|
var e_1, _a;
|
|
17
17
|
var _b, _c, _d;
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var f = split.join('/');
|
|
18
|
+
var file = _ref.file, type = _ref.type, dir = _ref.dir, cwd = _ref.cwd, fs = _ref.fs;
|
|
19
|
+
var folder = file;
|
|
21
20
|
try {
|
|
22
|
-
fs.accessSync(cwd + "/".concat(
|
|
21
|
+
fs.accessSync(cwd + "/".concat(folder), fs.F_OK, {
|
|
23
22
|
recursive: true
|
|
24
23
|
});
|
|
25
24
|
}
|
|
26
25
|
catch (e) {
|
|
27
|
-
fs.mkdirSync(cwd + "/".concat(
|
|
26
|
+
fs.mkdirSync(cwd + "/".concat(folder), {
|
|
28
27
|
recursive: true
|
|
29
28
|
});
|
|
30
29
|
}
|
|
31
30
|
try {
|
|
32
|
-
var
|
|
33
|
-
var files = (_b = fs.readdirSync(
|
|
31
|
+
var path = dir ? "".concat(cwd, "/").concat(dir, "/").concat(folder) : "".concat(cwd, "/").concat(folder);
|
|
32
|
+
var files = (_b = fs.readdirSync(path)) !== null && _b !== void 0 ? _b : [];
|
|
34
33
|
if (!(files === null || files === void 0 ? void 0 : files.length))
|
|
35
34
|
console.log('this folder is empty');
|
|
36
35
|
var cmd = type === '.js' ? 'node' : 'ts-node';
|
|
36
|
+
var sum = 0;
|
|
37
37
|
try {
|
|
38
38
|
for (var files_1 = __values(files), files_1_1 = files_1.next(); !files_1_1.done; files_1_1 = files_1.next()) {
|
|
39
|
-
var
|
|
40
|
-
var run = (0, child_process_1.exec)("".concat(cmd, " ").concat(
|
|
39
|
+
var _file = files_1_1.value;
|
|
40
|
+
var run = (0, child_process_1.exec)("".concat(cmd, " ").concat(path, "/").concat(_file));
|
|
41
41
|
(_c = run === null || run === void 0 ? void 0 : run.stdout) === null || _c === void 0 ? void 0 : _c.on('data', function (data) {
|
|
42
42
|
if (data)
|
|
43
43
|
console.log(data);
|
|
@@ -46,6 +46,7 @@ exports.default = (function (_ref) {
|
|
|
46
46
|
if (err)
|
|
47
47
|
console.error(err);
|
|
48
48
|
});
|
|
49
|
+
sum++;
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -55,6 +56,8 @@ exports.default = (function (_ref) {
|
|
|
55
56
|
}
|
|
56
57
|
finally { if (e_1) throw e_1.error; }
|
|
57
58
|
}
|
|
59
|
+
if (sum === file.length)
|
|
60
|
+
process.exit(0);
|
|
58
61
|
}
|
|
59
62
|
catch (err) {
|
|
60
63
|
console.log(err.message);
|
package/dist/cli/models/make.js
CHANGED
|
@@ -5,43 +5,42 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
var model_1 = __importDefault(require("./model"));
|
|
7
7
|
var table_1 = __importDefault(require("../tables/table"));
|
|
8
|
-
var
|
|
8
|
+
var pluralize_1 = __importDefault(require("pluralize"));
|
|
9
9
|
exports.default = (function (_ref) {
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
10
|
+
var file = _ref.file, migrate = _ref.migrate, dir = _ref.dir, type = _ref.type, cwd = _ref.cwd, fs = _ref.fs, npm = _ref.npm;
|
|
11
|
+
if (dir) {
|
|
12
|
+
try {
|
|
13
|
+
fs.accessSync(cwd + "/".concat(dir), fs.F_OK, {
|
|
14
|
+
recursive: true
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
fs.mkdirSync(cwd + "/".concat(dir), {
|
|
19
|
+
recursive: true
|
|
20
|
+
});
|
|
21
|
+
}
|
|
23
22
|
}
|
|
24
|
-
var
|
|
25
|
-
var data = (0, model_1.default)(
|
|
26
|
-
fs.writeFile(
|
|
23
|
+
var model = dir ? "".concat(cwd, "/").concat(dir, "/").concat(file).concat(type) : "".concat(cwd, "/").concat(file).concat(type);
|
|
24
|
+
var data = (0, model_1.default)(file, npm);
|
|
25
|
+
fs.writeFile(model, data, function (err) {
|
|
27
26
|
if (err)
|
|
28
27
|
throw err.message;
|
|
29
28
|
});
|
|
30
|
-
console.log("Model : '".concat(
|
|
29
|
+
console.log("Model : '".concat(file, "' created successfully"));
|
|
31
30
|
if (migrate) {
|
|
32
|
-
var tableName =
|
|
33
|
-
var
|
|
31
|
+
var tableName = (0, pluralize_1.default)(file.replace(/([A-Z])/g, function (str) { return '_' + str.toLowerCase(); }).slice(1));
|
|
32
|
+
var folder = dir ? "".concat(dir, "/Migrations") : "/Migrations";
|
|
34
33
|
try {
|
|
35
|
-
fs.accessSync(cwd +
|
|
34
|
+
fs.accessSync(cwd + folder, fs.F_OK, {
|
|
36
35
|
recursive: true
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
38
|
catch (e) {
|
|
40
|
-
fs.mkdirSync(cwd +
|
|
39
|
+
fs.mkdirSync(cwd + folder, {
|
|
41
40
|
recursive: true
|
|
42
41
|
});
|
|
43
42
|
}
|
|
44
|
-
var folderMigrate = "".concat(cwd, "/").concat(
|
|
43
|
+
var folderMigrate = "".concat(cwd, "/").concat(folder, "/create_").concat(tableName, "_table").concat(type);
|
|
45
44
|
var table = (0, table_1.default)(tableName, npm);
|
|
46
45
|
fs.writeFile(folderMigrate, table, function (err) {
|
|
47
46
|
if (err)
|
package/dist/cli/tables/make.js
CHANGED
|
@@ -5,28 +5,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
var table_1 = __importDefault(require("./table"));
|
|
7
7
|
exports.default = (function (_ref) {
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
recursive: true
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
fs.mkdirSync(cwd + "/".concat(f), {
|
|
21
|
-
recursive: true
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
var folderMigrate = "".concat(cwd, "/").concat(f, "/create_").concat(name, "_table").concat(type);
|
|
25
|
-
var table = (0, table_1.default)(name, npm);
|
|
26
|
-
fs.writeFile(folderMigrate, table, function (err) {
|
|
27
|
-
if (err)
|
|
28
|
-
console.log(err.message);
|
|
8
|
+
var file = _ref.file, type = _ref.type, cwd = _ref.cwd, dir = _ref.dir, fs = _ref.fs, npm = _ref.npm;
|
|
9
|
+
// if(name == null) {
|
|
10
|
+
// console.log(`use ${npm} make:migration <NAME TABLE> --dir=<DIRECTORY>`)
|
|
11
|
+
// process.exit(0);
|
|
12
|
+
// }
|
|
13
|
+
try {
|
|
14
|
+
fs.accessSync(cwd + "/".concat(file), fs.F_OK, {
|
|
15
|
+
recursive: true
|
|
29
16
|
});
|
|
30
|
-
console.log("Migration : ".concat(name, " created successfully"));
|
|
31
17
|
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
fs.mkdirSync(cwd + "/".concat(file), {
|
|
20
|
+
recursive: true
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
var folderMigrate = dir ? "".concat(cwd, "/").concat(dir, "/create_").concat(file, "_table").concat(type) : "".concat(cwd, "/create_").concat(file, "_table").concat(type);
|
|
24
|
+
var table = (0, table_1.default)(file, npm);
|
|
25
|
+
fs.writeFile(folderMigrate, table, function (err) {
|
|
26
|
+
if (err)
|
|
27
|
+
console.log(err.message);
|
|
28
|
+
});
|
|
29
|
+
console.log("Migration : ".concat(file, " created successfully"));
|
|
30
|
+
process.exit(0);
|
|
32
31
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const Table: (
|
|
1
|
+
declare const Table: (table: string, npm: string) => string;
|
|
2
2
|
export default Table;
|
package/dist/cli/tables/table.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var Table = function (
|
|
4
|
-
return "import { Schema , Blueprint , DB } from '".concat(npm, "'\n(async () => {\n await new Schema().table('").concat(
|
|
3
|
+
var Table = function (table, npm) {
|
|
4
|
+
return "import { Schema , Blueprint , DB } from '".concat(npm, "'\n(async () => {\n await new Schema().table('").concat(table, "',{ \n id : new Blueprint().int().notNull().primary().autoIncrement(),\n name : new Blueprint().varchar(120).default('my name'),\n email : new Blueprint().varchar(120).unique(),\n email_verify : new Blueprint().tinyInt(),\n password : new Blueprint().varchar(120),\n birthdate : new Blueprint().date(),\n created_at : new Blueprint().null().timestamp(),\n updated_at : new Blueprint().null().timestamp()\n })\n\n /**\n * \n * @Faker data\n * await new DB().table('").concat(table, "').faker(5)\n */\n})()\n");
|
|
5
5
|
};
|
|
6
6
|
exports.default = Table;
|
package/dist/lib/index.d.ts
CHANGED
package/dist/lib/index.js
CHANGED
package/dist/lib/tspace/DB.js
CHANGED
|
@@ -214,7 +214,8 @@ var DB = /** @class */ (function (_super) {
|
|
|
214
214
|
INSERT: '',
|
|
215
215
|
SELECT: '',
|
|
216
216
|
ONLY: [],
|
|
217
|
-
EXCEPT: [
|
|
217
|
+
EXCEPT: [],
|
|
218
|
+
CHUNK: 0,
|
|
218
219
|
COUNT: '',
|
|
219
220
|
FROM: '',
|
|
220
221
|
JOIN: '',
|
|
@@ -230,9 +231,11 @@ var DB = /** @class */ (function (_super) {
|
|
|
230
231
|
};
|
|
231
232
|
return {
|
|
232
233
|
get: function (key) {
|
|
233
|
-
if (key)
|
|
234
|
-
return db
|
|
235
|
-
|
|
234
|
+
if (key == null)
|
|
235
|
+
return db;
|
|
236
|
+
if (!db.hasOwnProperty(key))
|
|
237
|
+
throw new Error("can't get this [".concat(key, "]"));
|
|
238
|
+
return db[key];
|
|
236
239
|
},
|
|
237
240
|
set: function (key, value) {
|
|
238
241
|
if (!db.hasOwnProperty(key))
|
|
@@ -4,6 +4,9 @@ declare class Database extends AbstractDatabase {
|
|
|
4
4
|
only(...params: Array<string>): this;
|
|
5
5
|
distinct(column?: string): this;
|
|
6
6
|
select(...params: string[]): this;
|
|
7
|
+
chunk(chunk: number): this;
|
|
8
|
+
when(value: string | number | undefined | null, cb: Function): this;
|
|
9
|
+
whereRaw(query: string): this;
|
|
7
10
|
where(column: string, operator?: any, value?: any): this;
|
|
8
11
|
whereId(id: number): this;
|
|
9
12
|
whereEmail(email: string): this;
|
|
@@ -122,6 +125,7 @@ declare class Database extends AbstractDatabase {
|
|
|
122
125
|
max(column?: string): Promise<any>;
|
|
123
126
|
min(column?: string): Promise<any>;
|
|
124
127
|
delete(): Promise<boolean>;
|
|
128
|
+
forceDelete(): Promise<boolean>;
|
|
125
129
|
getGroupBy(column: string): Promise<any>;
|
|
126
130
|
findManyGroupBy(column: string): Promise<any>;
|
|
127
131
|
save(transaction?: {
|