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.
Files changed (42) hide show
  1. package/README.md +14 -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 +9 -9
  6. package/dist/cli/models/make.d.ts +4 -0
  7. package/dist/cli/models/make.js +14 -17
  8. package/dist/cli/models/model.d.ts +2 -0
  9. package/dist/cli/models/model.js +1 -1
  10. package/dist/cli/tables/make.d.ts +4 -0
  11. package/dist/cli/tables/make.js +21 -22
  12. package/dist/cli/tables/table.d.ts +2 -0
  13. package/dist/cli/tables/table.js +1 -1
  14. package/dist/lib/config/env.d.ts +8 -0
  15. package/dist/lib/config/env.js +1 -1
  16. package/dist/lib/connections/index.d.ts +2 -0
  17. package/dist/lib/connections/index.js +1 -1
  18. package/dist/lib/connections/options.d.ts +4 -0
  19. package/dist/lib/constants/index.d.ts +4 -0
  20. package/dist/lib/{utils/constant.js → constants/index.js} +0 -2
  21. package/dist/lib/index.d.ts +8 -0
  22. package/dist/lib/index.js +6 -2
  23. package/dist/lib/tspace/AbstractDB.d.ts +7 -0
  24. package/dist/lib/tspace/AbstractDatabase.d.ts +102 -0
  25. package/dist/lib/tspace/AbstractModel.d.ts +20 -0
  26. package/dist/lib/tspace/DB.d.ts +15 -0
  27. package/dist/lib/tspace/DB.js +10 -7
  28. package/dist/lib/tspace/Database.d.ts +155 -0
  29. package/dist/lib/tspace/Database.js +232 -168
  30. package/dist/lib/tspace/Interface.d.ts +25 -0
  31. package/dist/lib/tspace/Logger.d.ts +1 -0
  32. package/dist/lib/tspace/Logger.js +4 -3
  33. package/dist/lib/tspace/Model.d.ts +233 -0
  34. package/dist/lib/tspace/Model.js +247 -236
  35. package/dist/lib/tspace/ProxyHandler.d.ts +5 -0
  36. package/dist/lib/tspace/ProxyHandler.js +2 -2
  37. package/dist/lib/tspace/Schema.d.ts +45 -0
  38. package/dist/lib/tspace/Schema.js +9 -11
  39. package/dist/lib/tspace/index.d.ts +14 -0
  40. package/dist/lib/utils/index.d.ts +17 -0
  41. package/dist/lib/utils/index.js +8 -8
  42. package/package.json +3 -6
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ set: (target: any, name: string, value: any) => boolean;
3
+ get: (target: any, prop: any, value: any) => any;
4
+ };
5
+ export default _default;
@@ -17,7 +17,7 @@ exports.default = {
17
17
  var _a;
18
18
  var _b;
19
19
  if ((_b = target._setters) === null || _b === void 0 ? void 0 : _b.includes(name))
20
- throw new Error("no allow to set this " + name);
20
+ throw new Error("no allow to set this ".concat(name));
21
21
  target.$attributes = __assign(__assign({}, target.$attributes), (_a = {}, _a[name] = value, _a));
22
22
  return true;
23
23
  },
@@ -26,7 +26,7 @@ exports.default = {
26
26
  try {
27
27
  (0, Logger_1.LoggerMethod)(target, prop);
28
28
  switch (prop) {
29
- case 'attributes': return target["$" + prop];
29
+ case 'attributes': return target["$".concat(prop)];
30
30
  case 'logger': return (_a = target.$logger) === null || _a === void 0 ? void 0 : _a.get();
31
31
  case 'result': return (_b = target.$db) === null || _b === void 0 ? void 0 : _b.get('RESULT');
32
32
  default: return Reflect.get(target, prop, value);
@@ -0,0 +1,45 @@
1
+ import Database from "./Database";
2
+ export declare class Schema extends Database {
3
+ table: (table: string, schemas: {
4
+ [x: string]: any;
5
+ }) => Promise<void>;
6
+ }
7
+ export declare class Blueprint {
8
+ protected type: string | undefined;
9
+ protected attrbuites: Array<string>;
10
+ private _addType;
11
+ private _addAttrbuite;
12
+ /**
13
+ *
14
+ * @Types
15
+ *
16
+ */
17
+ int(): this;
18
+ tinyInt(n?: number): this;
19
+ bigInt(n?: number): this;
20
+ double(): this;
21
+ float(): this;
22
+ varchar(n?: number): this;
23
+ char(n?: number): this;
24
+ longText(): this;
25
+ mediumText(): this;
26
+ tinyText(): this;
27
+ text(): this;
28
+ enum(...n: Array<string>): this;
29
+ date(): this;
30
+ dateTime(): this;
31
+ timestamp(): this;
32
+ /**
33
+ *
34
+ * @Attrbuites
35
+ *
36
+ */
37
+ unsigned(): this;
38
+ unique(): this;
39
+ null(): this;
40
+ notNull(): this;
41
+ primary(): this;
42
+ default(n: string): this;
43
+ defaultTimestamp(): this;
44
+ autoIncrement(): this;
45
+ }
@@ -85,7 +85,6 @@ var Schema = /** @class */ (function (_super) {
85
85
  __extends(Schema, _super);
86
86
  function Schema() {
87
87
  var _this = _super !== null && _super.apply(this, arguments) || this;
88
- _this.timeStamp = ['created_at timestamp NULL', 'updated_at timestamp NULL'];
89
88
  _this.table = function (table, schemas) { return __awaiter(_this, void 0, void 0, function () {
90
89
  var columns, key, data, type, attrbuites, sql, err_1;
91
90
  var _a;
@@ -97,14 +96,13 @@ var Schema = /** @class */ (function (_super) {
97
96
  for (key in schemas) {
98
97
  data = schemas[key];
99
98
  type = data.type, attrbuites = data.attrbuites;
100
- columns = __spreadArray(__spreadArray([], __read(columns), false), [key + " " + type + " " + (attrbuites === null || attrbuites === void 0 ? void 0 : attrbuites.join(' '))], false);
99
+ columns = __spreadArray(__spreadArray([], __read(columns), false), ["".concat(key, " ").concat(type, " ").concat(attrbuites === null || attrbuites === void 0 ? void 0 : attrbuites.join(' '))], false);
101
100
  }
102
- columns = __spreadArray(__spreadArray([], __read(columns), false), __read(this.timeStamp), false);
103
- sql = "CREATE TABLE " + table + " (" + (columns === null || columns === void 0 ? void 0 : columns.join(',')) + ") ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8";
101
+ sql = "CREATE TABLE ".concat(table, " (").concat(columns === null || columns === void 0 ? void 0 : columns.join(','), ") ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8");
104
102
  return [4 /*yield*/, this.rawQuery(sql)];
105
103
  case 1:
106
104
  _b.sent();
107
- console.log("Migrats : '" + table + "' created successfully");
105
+ console.log("Migrats : '".concat(table, "' created successfully"));
108
106
  return [3 /*break*/, 3];
109
107
  case 2:
110
108
  err_1 = _b.sent();
@@ -144,12 +142,12 @@ var Blueprint = /** @class */ (function () {
144
142
  };
145
143
  Blueprint.prototype.tinyInt = function (n) {
146
144
  if (n === void 0) { n = 1; }
147
- this._addType("TINYINT(" + n + ")");
145
+ this._addType("TINYINT(".concat(n, ")"));
148
146
  return this;
149
147
  };
150
148
  Blueprint.prototype.bigInt = function (n) {
151
149
  if (n === void 0) { n = 10; }
152
- this._addType("BIGINT(" + n + ")");
150
+ this._addType("BIGINT(".concat(n, ")"));
153
151
  return this;
154
152
  };
155
153
  Blueprint.prototype.double = function () {
@@ -164,12 +162,12 @@ var Blueprint = /** @class */ (function () {
164
162
  if (n === void 0) { n = 100; }
165
163
  if (n > 255)
166
164
  n = 255;
167
- this._addType("VARCHAR(" + n + ")");
165
+ this._addType("VARCHAR(".concat(n, ")"));
168
166
  return this;
169
167
  };
170
168
  Blueprint.prototype.char = function (n) {
171
169
  if (n === void 0) { n = 1; }
172
- this._addType("CHAR(" + n + ")");
170
+ this._addType("CHAR(".concat(n, ")"));
173
171
  return this;
174
172
  };
175
173
  Blueprint.prototype.longText = function () {
@@ -193,7 +191,7 @@ var Blueprint = /** @class */ (function () {
193
191
  for (var _i = 0; _i < arguments.length; _i++) {
194
192
  n[_i] = arguments[_i];
195
193
  }
196
- this._addType("ENUM('" + n + "')");
194
+ this._addType("ENUM('".concat(n, "')"));
197
195
  return this;
198
196
  };
199
197
  Blueprint.prototype.date = function () {
@@ -234,7 +232,7 @@ var Blueprint = /** @class */ (function () {
234
232
  return this;
235
233
  };
236
234
  Blueprint.prototype.default = function (n) {
237
- this._addAttrbuite("DEFAULT '" + n + "'");
235
+ this._addAttrbuite("DEFAULT '".concat(n, "'"));
238
236
  return this;
239
237
  };
240
238
  Blueprint.prototype.defaultTimestamp = function () {
@@ -0,0 +1,14 @@
1
+ import DB from './DB';
2
+ import Model from './Model';
3
+ import { Schema, Blueprint } from './Schema';
4
+ export { DB };
5
+ export { Model };
6
+ export { Schema };
7
+ export { Blueprint };
8
+ declare const _default: {
9
+ DB: typeof DB;
10
+ Model: typeof Model;
11
+ Schema: typeof Schema;
12
+ Blueprint: typeof Blueprint;
13
+ };
14
+ export default _default;
@@ -0,0 +1,17 @@
1
+ declare const _default: {
2
+ consoleDebug: (message?: string | undefined) => void;
3
+ tableName: (name: string) => string;
4
+ faker: (value: string) => string | number | boolean;
5
+ connection: () => Promise<any>;
6
+ columnRelation: (name: string) => string;
7
+ timestamp: () => string;
8
+ date: () => string;
9
+ escape: (str: any) => any;
10
+ escapeSubQuery: (str: any) => any;
11
+ generateUUID: () => string;
12
+ constants: (name?: string | undefined) => string | Object | undefined;
13
+ covertBooleanToNumber: (data: any) => any;
14
+ snakeCase: (obj: any) => any;
15
+ camelCase: (obj: any) => any;
16
+ };
17
+ export default _default;
@@ -86,7 +86,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
86
86
  return (mod && mod.__esModule) ? mod : { "default": mod };
87
87
  };
88
88
  Object.defineProperty(exports, "__esModule", { value: true });
89
- var constant_1 = __importDefault(require("./constant"));
89
+ var constants_1 = __importDefault(require("../constants"));
90
90
  var connections_1 = __importDefault(require("../connections"));
91
91
  var timestamp = function () {
92
92
  var d = new Date();
@@ -96,7 +96,7 @@ var timestamp = function () {
96
96
  var hours = ("0" + d.getHours()).slice(-2);
97
97
  var minutes = ("0" + d.getMinutes()).slice(-2);
98
98
  var seconds = ("0" + d.getSeconds()).slice(-2);
99
- var now = year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds;
99
+ var now = "".concat(year, "-").concat(month, "-").concat(date, " ").concat(hours, ":").concat(minutes, ":").concat(seconds);
100
100
  return now;
101
101
  };
102
102
  var date = function () {
@@ -104,7 +104,7 @@ var date = function () {
104
104
  var year = d.getFullYear();
105
105
  var month = ("0" + (d.getMonth() + 1)).slice(-2);
106
106
  var date = ("0" + d.getDate()).slice(-2);
107
- var now = year + "-" + month + "-" + date;
107
+ var now = "".concat(year, "-").concat(month, "-").concat(date);
108
108
  return now;
109
109
  };
110
110
  var escape = function (str) {
@@ -146,10 +146,10 @@ var columnRelation = function (name) {
146
146
  if (matches.length > 1) {
147
147
  matches.forEach(function (matche, i) {
148
148
  if (i > 0)
149
- name = name.replace(matche, "_" + matche.toUpperCase());
149
+ name = name.replace(matche, "_".concat(matche.toUpperCase()));
150
150
  });
151
151
  }
152
- return "" + name.toLocaleLowerCase();
152
+ return "".concat(name.toLocaleLowerCase());
153
153
  };
154
154
  var generateUUID = function () {
155
155
  var date = +new Date();
@@ -162,9 +162,9 @@ var generateUUID = function () {
162
162
  var constants = function (name) {
163
163
  var e_1, _a;
164
164
  if (!name)
165
- return constant_1.default;
165
+ return constants_1.default;
166
166
  try {
167
- for (var _b = __values(Object === null || Object === void 0 ? void 0 : Object.entries(constant_1.default)), _c = _b.next(); !_c.done; _c = _b.next()) {
167
+ for (var _b = __values(Object === null || Object === void 0 ? void 0 : Object.entries(constants_1.default)), _c = _b.next(); !_c.done; _c = _b.next()) {
168
168
  var _d = __read(_c.value, 2), index = _d[0], _const = _d[1];
169
169
  if (index === name)
170
170
  return _const;
@@ -246,7 +246,7 @@ var camelCase = function (obj) {
246
246
  var consoleDebug = function (message) {
247
247
  if (message == null)
248
248
  return;
249
- console.log("SQL Statement: \u001B[33m" + message + " \u001B[0m ");
249
+ console.log("SQL Statement: \u001B[33m".concat(message, " \u001B[0m "));
250
250
  };
251
251
  var connection = function () { return __awaiter(void 0, void 0, void 0, function () {
252
252
  return __generator(this, function (_a) {
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "tspace-mysql",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "description": "mysql query builder object relational mapping",
5
- "main": "./dist/lib/index.js",
5
+ "main": "dist/lib/index.js",
6
6
  "types": "dist/lib/index.d.ts",
7
7
  "files": [
8
8
  "dist"
@@ -39,10 +39,7 @@
39
39
  "homepage": "https://github.com/thanathip41",
40
40
  "scripts": {
41
41
  "build": "tsc",
42
- "prepare": "npm run build",
43
- "test" : "ts-node test/index.ts",
44
- "dev" : "set NODE_ENV=development&&ts-node test/index.ts",
45
- "prod" : "set NODE_ENV=production&&ts-node test/index.ts"
42
+ "prepare": "npm run build"
46
43
  },
47
44
  "devDependencies": {
48
45
  "@types/mysql": "^2.15.19",