tspace-mysql 1.0.0 → 1.0.3
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 +14 -15
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +10 -6
- package/dist/cli/migrate/make.d.ts +4 -0
- package/dist/cli/migrate/make.js +9 -9
- package/dist/cli/models/make.d.ts +4 -0
- package/dist/cli/models/make.js +14 -17
- package/dist/cli/models/model.d.ts +2 -0
- package/dist/cli/models/model.js +1 -1
- package/dist/cli/tables/make.d.ts +4 -0
- package/dist/cli/tables/make.js +21 -22
- package/dist/cli/tables/table.d.ts +2 -0
- package/dist/cli/tables/table.js +1 -1
- package/dist/lib/config/env.d.ts +8 -0
- package/dist/lib/config/env.js +1 -1
- package/dist/lib/connections/index.d.ts +2 -0
- package/dist/lib/connections/index.js +1 -1
- package/dist/lib/connections/options.d.ts +4 -0
- package/dist/lib/constants/index.d.ts +4 -0
- package/dist/lib/{utils/constant.js → constants/index.js} +0 -2
- package/dist/lib/index.d.ts +8 -0
- package/dist/lib/index.js +6 -2
- package/dist/lib/tspace/AbstractDB.d.ts +7 -0
- package/dist/lib/tspace/AbstractDatabase.d.ts +102 -0
- package/dist/lib/tspace/AbstractModel.d.ts +20 -0
- package/dist/lib/tspace/DB.d.ts +15 -0
- package/dist/lib/tspace/DB.js +10 -7
- package/dist/lib/tspace/Database.d.ts +155 -0
- package/dist/lib/tspace/Database.js +232 -168
- package/dist/lib/tspace/Interface.d.ts +25 -0
- package/dist/lib/tspace/Logger.d.ts +1 -0
- package/dist/lib/tspace/Logger.js +4 -3
- package/dist/lib/tspace/Model.d.ts +233 -0
- package/dist/lib/tspace/Model.js +247 -236
- package/dist/lib/tspace/ProxyHandler.d.ts +5 -0
- package/dist/lib/tspace/ProxyHandler.js +2 -2
- package/dist/lib/tspace/Schema.d.ts +45 -0
- package/dist/lib/tspace/Schema.js +9 -11
- package/dist/lib/tspace/index.d.ts +14 -0
- package/dist/lib/utils/index.d.ts +17 -0
- package/dist/lib/utils/index.js +8 -8
- package/package.json +3 -6
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
|
|
@@ -335,7 +334,7 @@ import { Schema , Blueprint , DB } from 'tspace-mysql'
|
|
|
335
334
|
*/
|
|
336
335
|
})()
|
|
337
336
|
```
|
|
338
|
-
tspace-mysql migrate App/Models
|
|
337
|
+
tspace-mysql migrate Migrations --dir=App/Models
|
|
339
338
|
/* migrate all table in folder into database */
|
|
340
339
|
```js
|
|
341
340
|
* 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,28 @@ 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 +
|
|
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 +
|
|
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';
|
|
37
36
|
try {
|
|
38
37
|
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)(cmd
|
|
38
|
+
var _file = files_1_1.value;
|
|
39
|
+
var run = (0, child_process_1.exec)("".concat(cmd, " ").concat(path, "/").concat(_file));
|
|
41
40
|
(_c = run === null || run === void 0 ? void 0 : run.stdout) === null || _c === void 0 ? void 0 : _c.on('data', function (data) {
|
|
42
41
|
if (data)
|
|
43
42
|
console.log(data);
|
|
@@ -55,6 +54,7 @@ exports.default = (function (_ref) {
|
|
|
55
54
|
}
|
|
56
55
|
finally { if (e_1) throw e_1.error; }
|
|
57
56
|
}
|
|
57
|
+
process.exit(0);
|
|
58
58
|
}
|
|
59
59
|
catch (err) {
|
|
60
60
|
console.log(err.message);
|
package/dist/cli/models/make.js
CHANGED
|
@@ -5,48 +5,45 @@ 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
|
-
var split = path.split('/') || path;
|
|
12
|
-
var model = split.pop();
|
|
13
|
-
var f = split.join('/');
|
|
10
|
+
var file = _ref.file, migrate = _ref.migrate, dir = _ref.dir, type = _ref.type, cwd = _ref.cwd, fs = _ref.fs, npm = _ref.npm;
|
|
14
11
|
try {
|
|
15
|
-
fs.accessSync(cwd +
|
|
12
|
+
fs.accessSync(cwd + "/".concat(file), fs.F_OK, {
|
|
16
13
|
recursive: true
|
|
17
14
|
});
|
|
18
15
|
}
|
|
19
16
|
catch (e) {
|
|
20
|
-
fs.mkdirSync(cwd +
|
|
17
|
+
fs.mkdirSync(cwd + "/".concat(file), {
|
|
21
18
|
recursive: true
|
|
22
19
|
});
|
|
23
20
|
}
|
|
24
|
-
var
|
|
25
|
-
var data = (0, model_1.default)(
|
|
26
|
-
fs.writeFile(
|
|
21
|
+
var model = dir ? "".concat(cwd, "/").concat(dir, "/").concat(file).concat(type) : "".concat(cwd, "/").concat(file, "/").concat(file).concat(type);
|
|
22
|
+
var data = (0, model_1.default)(file, npm);
|
|
23
|
+
fs.writeFile(model, data, function (err) {
|
|
27
24
|
if (err)
|
|
28
25
|
throw err.message;
|
|
29
26
|
});
|
|
30
|
-
console.log("Model : '"
|
|
27
|
+
console.log("Model : '".concat(file, "' created successfully"));
|
|
31
28
|
if (migrate) {
|
|
32
|
-
var tableName =
|
|
33
|
-
var
|
|
29
|
+
var tableName = (0, pluralize_1.default)(file.replace(/([A-Z])/g, function (str) { return '_' + str.toLowerCase(); }).slice(1));
|
|
30
|
+
var folder = dir ? "".concat(dir, "/Migrations") : "/Migrations";
|
|
34
31
|
try {
|
|
35
|
-
fs.accessSync(cwd +
|
|
32
|
+
fs.accessSync(cwd + folder, fs.F_OK, {
|
|
36
33
|
recursive: true
|
|
37
34
|
});
|
|
38
35
|
}
|
|
39
36
|
catch (e) {
|
|
40
|
-
fs.mkdirSync(cwd +
|
|
37
|
+
fs.mkdirSync(cwd + folder, {
|
|
41
38
|
recursive: true
|
|
42
39
|
});
|
|
43
40
|
}
|
|
44
|
-
var folderMigrate = cwd
|
|
41
|
+
var folderMigrate = "".concat(cwd, "/").concat(folder, "/create_").concat(tableName, "_table").concat(type);
|
|
45
42
|
var table = (0, table_1.default)(tableName, npm);
|
|
46
43
|
fs.writeFile(folderMigrate, table, function (err) {
|
|
47
44
|
if (err)
|
|
48
45
|
throw err;
|
|
49
46
|
});
|
|
50
|
-
console.log("Migration : '"
|
|
47
|
+
console.log("Migration : '".concat(tableName, "' created successfully"));
|
|
51
48
|
}
|
|
52
49
|
});
|
package/dist/cli/models/model.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var Model = function (model, npm) {
|
|
4
|
-
return "import { Model } from '"
|
|
4
|
+
return "import { Model } from '".concat(npm, "'\nclass ").concat(model, " extends Model {\n constructor(){\n super()\n this.useTimestamp()\n }\n}\nexport { ").concat(model, " }\nexport default ").concat(model, "\n");
|
|
5
5
|
};
|
|
6
6
|
exports.default = Model;
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
recursive: true
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
var folderMigrate = cwd + "/" + f + "/create_" + name + "_table" + 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, name = _ref.name, type = _ref.type, cwd = _ref.cwd, dir = _ref.dir, fs = _ref.fs, npm = _ref.npm;
|
|
9
|
+
if (name == null) {
|
|
10
|
+
console.log("use ".concat(npm, " make:table FOLDER/FOLDER --name=tableName"));
|
|
11
|
+
process.exit(0);
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
fs.accessSync(cwd + "/".concat(file), fs.F_OK, {
|
|
15
|
+
recursive: true
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
fs.mkdirSync(cwd + "/".concat(file), {
|
|
20
|
+
recursive: true
|
|
29
21
|
});
|
|
30
|
-
console.log("Migration : " + name + " created successfully");
|
|
31
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)(name, npm);
|
|
25
|
+
fs.writeFile(folderMigrate, table, function (err) {
|
|
26
|
+
if (err)
|
|
27
|
+
console.log(err.message);
|
|
28
|
+
});
|
|
29
|
+
console.log("Migration : ".concat(name, " created successfully"));
|
|
30
|
+
process.exit(0);
|
|
32
31
|
});
|
package/dist/cli/tables/table.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var Table = function (model, npm) {
|
|
4
|
-
return "import { Schema , Blueprint , DB } from '"
|
|
4
|
+
return "import { Schema , Blueprint , DB } from '".concat(npm, "'\n(async () => {\n await new Schema().table('").concat(model, "',{ \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(model, "').faker(5)\n */\n})()\n");
|
|
5
5
|
};
|
|
6
6
|
exports.default = Table;
|
package/dist/lib/config/env.js
CHANGED
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
var dotenv_1 = __importDefault(require("dotenv"));
|
|
8
8
|
var path_1 = __importDefault(require("path"));
|
|
9
9
|
var NODE_ENV = (_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV;
|
|
10
|
-
var pathEnv = path_1.default.join(path_1.default.resolve(), ".env."
|
|
10
|
+
var pathEnv = path_1.default.join(path_1.default.resolve(), ".env.".concat(NODE_ENV));
|
|
11
11
|
if (NODE_ENV == null)
|
|
12
12
|
pathEnv = path_1.default.join(path_1.default.resolve(), ".env");
|
|
13
13
|
dotenv_1.default.config({ path: pathEnv });
|
|
@@ -32,7 +32,7 @@ var messsage = optionIsNull ?
|
|
|
32
32
|
"Connection lost to database !";
|
|
33
33
|
pool.getConnection(function (err, connection) {
|
|
34
34
|
if (err) {
|
|
35
|
-
console.log("\u001B[1m\u001B[31m\n "
|
|
35
|
+
console.log("\u001B[1m\u001B[31m\n ".concat(messsage, " \u001B[0m\n ------------------------------- \u001B[33m\n DB_HOST : ").concat(options_1.default === null || options_1.default === void 0 ? void 0 : options_1.default.host, " \n DB_PORT : ").concat(options_1.default === null || options_1.default === void 0 ? void 0 : options_1.default.port, " \n DB_USERNAME : ").concat(options_1.default.user, " \n DB_PASSWORD : ").concat(options_1.default.password, " \n DB_DATABASE : ").concat(options_1.default.database, " \u001B[0m \n -------------------------------\n "));
|
|
36
36
|
}
|
|
37
37
|
if (connection)
|
|
38
38
|
connection.release();
|
package/dist/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -25,7 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
29
|
/**
|
|
26
30
|
* The entry point.
|
|
27
31
|
*
|
|
28
|
-
* @module tspace-
|
|
32
|
+
* @module tspace-mysql
|
|
29
33
|
*/
|
|
30
34
|
var tspace = __importStar(require("./tspace"));
|
|
31
35
|
__exportStar(require("./tspace"), exports);
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
declare abstract class AbstractDatabase {
|
|
2
|
+
protected _setters: string[];
|
|
3
|
+
protected $utils: Function;
|
|
4
|
+
protected $db: {
|
|
5
|
+
get: Function;
|
|
6
|
+
set: Function;
|
|
7
|
+
};
|
|
8
|
+
protected $logger: {
|
|
9
|
+
get: Function;
|
|
10
|
+
set: (arg: string) => void;
|
|
11
|
+
check: (arg: string) => boolean;
|
|
12
|
+
};
|
|
13
|
+
protected $attributes: {};
|
|
14
|
+
abstract debug(): void;
|
|
15
|
+
abstract dump(): void;
|
|
16
|
+
abstract dd(): void;
|
|
17
|
+
abstract select(...params: string[]): void;
|
|
18
|
+
abstract distinct(...params: string[]): void;
|
|
19
|
+
abstract whereNull(column: string): void;
|
|
20
|
+
abstract whereNotNull(column: string): void;
|
|
21
|
+
abstract where(column: string, operator: string, value: string): void;
|
|
22
|
+
abstract whereSensitive(column: string, operator: string, value: string): void;
|
|
23
|
+
abstract whereId(id: number): void;
|
|
24
|
+
abstract whereUser(id: number): void;
|
|
25
|
+
abstract whereEmail(value: string): void;
|
|
26
|
+
abstract whereGroupStart(column: string, operator: string, value: string): void;
|
|
27
|
+
abstract whereGroupEnd(column: string, operator: string, value: string): void;
|
|
28
|
+
abstract orWhereGroupStart(column: string, operator: string, value: string): void;
|
|
29
|
+
abstract orWhereGroupEnd(column: string, operator: string, value: string): void;
|
|
30
|
+
abstract orWhere(column: string, operator: string, value: string): void;
|
|
31
|
+
abstract whereIn(column: string, arrayValues: Array<any>): void;
|
|
32
|
+
abstract orWhereIn(column: string, arrayValues: Array<any>): void;
|
|
33
|
+
abstract whereNotIn(column: string, arrayValues: Array<any>): void;
|
|
34
|
+
abstract whereSubQuery(column: string, subQuery: string): void;
|
|
35
|
+
abstract whereNotInSubQuery(column: string, subQuery: string): void;
|
|
36
|
+
abstract orWhereSubQuery(column: string, subQuery: string): void;
|
|
37
|
+
abstract whereBetween(column: string, arrayValue: Array<any>): void;
|
|
38
|
+
abstract having(condition: string): void;
|
|
39
|
+
abstract join(pk: string, fk: string): void;
|
|
40
|
+
abstract rightJoin(pk: string, fk: string): void;
|
|
41
|
+
abstract leftJoin(pk: string, fk: string): void;
|
|
42
|
+
abstract crossJoin(pk: string, fk: string): void;
|
|
43
|
+
abstract orderBy(column: string, order: string): void;
|
|
44
|
+
abstract latest(column: string): void;
|
|
45
|
+
abstract oldest(column: string): void;
|
|
46
|
+
abstract groupBy(column: string): void;
|
|
47
|
+
abstract limit(number: number): void;
|
|
48
|
+
abstract hidden(...columns: string[]): void;
|
|
49
|
+
abstract insert(objects: object): void;
|
|
50
|
+
abstract create(objects: object): void;
|
|
51
|
+
abstract update(objects: object): void;
|
|
52
|
+
abstract insertNotExists(objects: object): void;
|
|
53
|
+
abstract createNotExists(objects: object): void;
|
|
54
|
+
abstract upsert(objects: object): void;
|
|
55
|
+
abstract insertOrUpdate(objects: object): void;
|
|
56
|
+
abstract createOrUpdate(objects: object): void;
|
|
57
|
+
abstract updateOrInsert(objects: object): void;
|
|
58
|
+
abstract updateOrCreate(objects: object): void;
|
|
59
|
+
abstract createMultiple(objects: object): void;
|
|
60
|
+
abstract insertMultiple(objects: object): void;
|
|
61
|
+
abstract except(...params: string[]): void;
|
|
62
|
+
abstract only(...params: string[]): void;
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @Execute result
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
abstract drop(): Promise<any>;
|
|
69
|
+
abstract truncate(): Promise<any>;
|
|
70
|
+
abstract all(): Promise<any>;
|
|
71
|
+
abstract find(id: number): Promise<any>;
|
|
72
|
+
abstract pagination({ limit, page }: {
|
|
73
|
+
limit: number;
|
|
74
|
+
page: number;
|
|
75
|
+
}): Promise<any>;
|
|
76
|
+
abstract paginate({ limit, page }: {
|
|
77
|
+
limit: number;
|
|
78
|
+
page: number;
|
|
79
|
+
}): Promise<any>;
|
|
80
|
+
abstract first(): Promise<any>;
|
|
81
|
+
abstract get(): Promise<any>;
|
|
82
|
+
abstract findOne(): Promise<any>;
|
|
83
|
+
abstract findMany(): Promise<any>;
|
|
84
|
+
abstract getGroupBy(column: string): Promise<any>;
|
|
85
|
+
abstract findManyGroupBy(column: string): Promise<any>;
|
|
86
|
+
abstract toArray(column: string): Promise<any>;
|
|
87
|
+
abstract toJSON(): Promise<any>;
|
|
88
|
+
abstract toSQL(): string;
|
|
89
|
+
abstract toString(): string;
|
|
90
|
+
abstract count(column: string): Promise<any>;
|
|
91
|
+
abstract sum(column: string): Promise<any>;
|
|
92
|
+
abstract avg(column: string): Promise<any>;
|
|
93
|
+
abstract max(column: string): Promise<any>;
|
|
94
|
+
abstract min(column: string): Promise<any>;
|
|
95
|
+
abstract delete(): Promise<any>;
|
|
96
|
+
abstract exists(): Promise<any>;
|
|
97
|
+
abstract save(): Promise<any>;
|
|
98
|
+
abstract increment(column: string, value: number): Promise<any>;
|
|
99
|
+
abstract decrement(column: string, value: number): Promise<any>;
|
|
100
|
+
abstract faker(round: number): Promise<any>;
|
|
101
|
+
}
|
|
102
|
+
export default AbstractDatabase;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Relation } from './Interface';
|
|
2
|
+
import Database from './Database';
|
|
3
|
+
declare abstract class AbstractModel extends Database {
|
|
4
|
+
abstract useDebug(): void;
|
|
5
|
+
abstract useTable(table: string): void;
|
|
6
|
+
abstract useTimestamp(): void;
|
|
7
|
+
abstract useSoftDelete(): void;
|
|
8
|
+
abstract usePattern(pattern: string): void;
|
|
9
|
+
abstract onlyTrashed(): void;
|
|
10
|
+
abstract trashed(): void;
|
|
11
|
+
abstract restore(): void;
|
|
12
|
+
abstract with(...nameRelations: string[]): void;
|
|
13
|
+
abstract withQuery(nameRelations: string, callback: Function): void;
|
|
14
|
+
abstract withExists(...nameRelations: string[]): void;
|
|
15
|
+
abstract hasOne({ name, model, pk, fk, freezeTable, child }: Relation): void;
|
|
16
|
+
abstract hasMany({ name, model, pk, fk, freezeTable, child }: Relation): void;
|
|
17
|
+
abstract belongsTo({ name, model, pk, fk, freezeTable, child }: Relation): void;
|
|
18
|
+
abstract belongsToMany({ name, model, pk, fk, freezeTable, child }: Relation): void;
|
|
19
|
+
}
|
|
20
|
+
export default AbstractModel;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import AbstractDB from './AbstractDB';
|
|
2
|
+
declare class DB extends AbstractDB {
|
|
3
|
+
[x: string]: {};
|
|
4
|
+
constructor();
|
|
5
|
+
table(table: string): this;
|
|
6
|
+
raw(sql: string): Promise<any[]>;
|
|
7
|
+
beginTransaction(): Promise<{
|
|
8
|
+
rollback: () => Promise<boolean>;
|
|
9
|
+
query: never[];
|
|
10
|
+
}>;
|
|
11
|
+
private _initDB;
|
|
12
|
+
private _setupLogger;
|
|
13
|
+
private _setupDB;
|
|
14
|
+
}
|
|
15
|
+
export default DB;
|
package/dist/lib/tspace/DB.js
CHANGED
|
@@ -100,9 +100,9 @@ var DB = /** @class */ (function (_super) {
|
|
|
100
100
|
return new Proxy(_this, ProxyHandler_1.default);
|
|
101
101
|
}
|
|
102
102
|
DB.prototype.table = function (table) {
|
|
103
|
-
this.$db.set('SELECT', this.$utils().constants('SELECT')
|
|
103
|
+
this.$db.set('SELECT', "".concat(this.$utils().constants('SELECT'), " *"));
|
|
104
104
|
this.$db.set('TABLE_NAME', table);
|
|
105
|
-
this.$db.set('FROM', ""
|
|
105
|
+
this.$db.set('FROM', "".concat(this.$utils().constants('FROM')));
|
|
106
106
|
return this;
|
|
107
107
|
};
|
|
108
108
|
DB.prototype.raw = function (sql) {
|
|
@@ -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,13 +231,15 @@ 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))
|
|
239
|
-
throw new Error("can't set this ["
|
|
242
|
+
throw new Error("can't set this [".concat(key, "]"));
|
|
240
243
|
db[key] = value;
|
|
241
244
|
return;
|
|
242
245
|
}
|