tspace-mysql 1.0.1 → 1.0.4

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.
Files changed (38) hide show
  1. package/README.md +16 -15
  2. package/dist/cli/index.d.ts +2 -0
  3. package/dist/cli/index.js +10 -6
  4. package/dist/cli/migrate/make.d.ts +4 -0
  5. package/dist/cli/migrate/make.js +8 -9
  6. package/dist/cli/models/make.d.ts +4 -0
  7. package/dist/cli/models/make.js +22 -23
  8. package/dist/cli/models/model.d.ts +2 -0
  9. package/dist/cli/tables/make.d.ts +4 -0
  10. package/dist/cli/tables/make.js +21 -22
  11. package/dist/cli/tables/table.d.ts +2 -0
  12. package/dist/cli/tables/table.js +1 -1
  13. package/dist/lib/config/env.d.ts +8 -0
  14. package/dist/lib/connections/index.d.ts +2 -0
  15. package/dist/lib/connections/options.d.ts +4 -0
  16. package/dist/lib/constants/index.d.ts +4 -0
  17. package/dist/lib/{utils/constant.js → constants/index.js} +0 -2
  18. package/dist/lib/index.d.ts +8 -0
  19. package/dist/lib/index.js +1 -1
  20. package/dist/lib/tspace/AbstractDB.d.ts +7 -0
  21. package/dist/lib/tspace/AbstractDatabase.d.ts +102 -0
  22. package/dist/lib/tspace/AbstractModel.d.ts +20 -0
  23. package/dist/lib/tspace/DB.d.ts +15 -0
  24. package/dist/lib/tspace/DB.js +7 -4
  25. package/dist/lib/tspace/Database.d.ts +155 -0
  26. package/dist/lib/tspace/Database.js +122 -58
  27. package/dist/lib/tspace/Interface.d.ts +25 -0
  28. package/dist/lib/tspace/Logger.d.ts +1 -0
  29. package/dist/lib/tspace/Logger.js +4 -3
  30. package/dist/lib/tspace/Model.d.ts +233 -0
  31. package/dist/lib/tspace/Model.js +139 -136
  32. package/dist/lib/tspace/ProxyHandler.d.ts +5 -0
  33. package/dist/lib/tspace/Schema.d.ts +45 -0
  34. package/dist/lib/tspace/Schema.js +0 -2
  35. package/dist/lib/tspace/index.d.ts +14 -0
  36. package/dist/lib/utils/index.d.ts +17 -0
  37. package/dist/lib/utils/index.js +3 -3
  38. 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 <folder/name model> --m --f=... --name=.... --js
269
+ tspace-mysql make:model <MODEL NAME> --m --dir=... --js
270
270
  * optional
271
- --m /* created table for migrate in <FOLDER/migrations> */
272
- --f=folder/...folder /* created table for migrate in <CUSTOM FOLDER> default <FOLDER/migrations> */
273
- --js /* extension .js default .ts */
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:table <folder> --name=....
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 .js default .ts */
277
+ --type=js /* extension js default ts */
278
+ --dir=directory /* created table in directory */
281
279
 
282
- tspace-mysql migrate <folder> --js
280
+ tspace-mysql migrate <FOLDER> --js
283
281
  * optional
284
- --js /* extension .js default .ts */
282
+ --type=js /* extension js default ts */
283
+ --dir=directory /* find migrate in directory */
285
284
  ```
286
285
 
287
- tspace-mysql make:model App/Models/User --m
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:table App/Models/Migrations --name=users
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/Migrations
339
+ tspace-mysql migrate Migrations --dir=App/Models
339
340
  /* migrate all table in folder into database */
340
341
  ```js
341
342
  * Blueprint method
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
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 migrateFolder = (_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('--f='); })) === null || _g === void 0 ? void 0 : _g.replace('--f=', '/')) !== null && _h !== void 0 ? _h : null;
21
- var path = (_j = process.argv.slice(3)) === null || _j === void 0 ? void 0 : _j.shift();
22
- var type = ((_l = (_k = process.argv.slice(2)) === null || _k === void 0 ? void 0 : _k.includes('--js')) !== null && _l !== void 0 ? _l : false) ? '.js' : '.ts';
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
- path: path,
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,
@@ -0,0 +1,4 @@
1
+ declare const _default: (_ref: {
2
+ [x: string]: any;
3
+ }) => void;
4
+ export default _default;
@@ -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 path = _ref.path, type = _ref.type, cwd = _ref.cwd, fs = _ref.fs;
19
- var split = path.split('/') || path;
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(f), fs.F_OK, {
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(f), {
26
+ fs.mkdirSync(cwd + "/".concat(folder), {
28
27
  recursive: true
29
28
  });
30
29
  }
31
30
  try {
32
- var dir = "".concat(cwd, "/").concat(f);
33
- var files = (_b = fs.readdirSync(dir)) !== null && _b !== void 0 ? _b : [];
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 t = files_1_1.value;
40
- var run = (0, child_process_1.exec)("".concat(cmd, " ").concat(dir, "/").concat(t));
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);
@@ -0,0 +1,4 @@
1
+ declare const _default: (_ref: {
2
+ [x: string]: any;
3
+ }) => void;
4
+ export default _default;
@@ -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 utils_1 = __importDefault(require("../../lib/utils"));
8
+ var pluralize_1 = __importDefault(require("pluralize"));
9
9
  exports.default = (function (_ref) {
10
- var path = _ref.path, migrate = _ref.migrate, migrateFolder = _ref.migrateFolder, type = _ref.type, name = _ref.name, cwd = _ref.cwd, fs = _ref.fs, npm = _ref.npm;
11
- var split = path.split('/') || path;
12
- var model = split.pop();
13
- var f = split.join('/');
14
- try {
15
- fs.accessSync(cwd + "/".concat(f), fs.F_OK, {
16
- recursive: true
17
- });
18
- }
19
- catch (e) {
20
- fs.mkdirSync(cwd + "/".concat(f), {
21
- recursive: true
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 folder = "".concat(cwd, "/").concat(f, "/").concat(model).concat(type);
25
- var data = (0, model_1.default)(name || model, npm);
26
- fs.writeFile(folder, data, function (err) {
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(model, "' created successfully"));
29
+ console.log("Model : '".concat(file, "' created successfully"));
31
30
  if (migrate) {
32
- var tableName = utils_1.default.tableName(name || model);
33
- var folder_1 = migrateFolder !== null && migrateFolder !== void 0 ? migrateFolder : "/".concat(f, "/Migrations");
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 + folder_1, fs.F_OK, {
34
+ fs.accessSync(cwd + folder, fs.F_OK, {
36
35
  recursive: true
37
36
  });
38
37
  }
39
38
  catch (e) {
40
- fs.mkdirSync(cwd + folder_1, {
39
+ fs.mkdirSync(cwd + folder, {
41
40
  recursive: true
42
41
  });
43
42
  }
44
- var folderMigrate = "".concat(cwd, "/").concat(folder_1, "/create_").concat(tableName, "_table").concat(type);
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)
@@ -0,0 +1,2 @@
1
+ declare const Model: (model: string, npm: string) => string;
2
+ export default Model;
@@ -0,0 +1,4 @@
1
+ declare const _default: (_ref: {
2
+ [x: string]: any;
3
+ }) => never;
4
+ export default _default;
@@ -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 path = _ref.path, name = _ref.name, type = _ref.type, cwd = _ref.cwd, fs = _ref.fs, npm = _ref.npm;
9
- var split = path.split('/') || path;
10
- var f = split.join('/');
11
- if (name == null)
12
- console.log("use ".concat(npm, " make:table FOLDER/FOLDER --name=tableName"));
13
- else {
14
- try {
15
- fs.accessSync(cwd + "/".concat(f), fs.F_OK, {
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, 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 ${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)(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
  });
@@ -0,0 +1,2 @@
1
+ declare const Table: (model: string, npm: string) => string;
2
+ export default Table;
@@ -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 '".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 })\n\n /**\n * \n * @Faker data\n * await new DB().table('").concat(model, "').faker(5)\n */\n})()\n");
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;
@@ -0,0 +1,8 @@
1
+ declare const env: Readonly<{
2
+ DB_HOST: string | undefined;
3
+ DB_PORT: string | undefined;
4
+ DB_USERNAME: string | undefined;
5
+ DB_PASSWORD: string | undefined;
6
+ DB_DATABASE: string | undefined;
7
+ }>;
8
+ export default env;
@@ -0,0 +1,2 @@
1
+ declare const pool: any;
2
+ export default pool;
@@ -0,0 +1,4 @@
1
+ declare const configs: {
2
+ [x: string]: Object | undefined;
3
+ };
4
+ export default configs;
@@ -0,0 +1,4 @@
1
+ declare const constant: {
2
+ [x: string]: string | Object;
3
+ };
4
+ export default constant;
@@ -5,8 +5,6 @@ var constant = Object.freeze({
5
5
  SHOW: 'SHOW',
6
6
  FIELDS: 'FIELDS',
7
7
  COLUMNS: 'COLUMNS',
8
- MYSQL: 'mysql',
9
- POSTGRESQL: 'pg',
10
8
  WHERE: 'WHERE',
11
9
  BETWEEN: 'BETWEEN',
12
10
  AND: 'AND',
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The entry point.
3
+ *
4
+ * @module tspace-mysql
5
+ */
6
+ import * as tspace from './tspace';
7
+ export * from './tspace';
8
+ export default tspace;
package/dist/lib/index.js CHANGED
@@ -29,7 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  /**
30
30
  * The entry point.
31
31
  *
32
- * @module tspace-myorm
32
+ * @module tspace-mysql
33
33
  */
34
34
  var tspace = __importStar(require("./tspace"));
35
35
  __exportStar(require("./tspace"), exports);
@@ -0,0 +1,7 @@
1
+ import Database from './Database';
2
+ declare abstract class AbstractDB extends Database {
3
+ abstract table(tableName: string): void;
4
+ abstract raw(sql: string): Promise<any>;
5
+ abstract beginTransaction(): Promise<any>;
6
+ }
7
+ export default AbstractDB;
@@ -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;
@@ -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[key];
235
- return db;
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))