tspace-mysql 1.0.0

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.
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ var Logger_1 = require("./Logger");
15
+ exports.default = {
16
+ set: function (target, name, value) {
17
+ var _a;
18
+ var _b;
19
+ if ((_b = target._setters) === null || _b === void 0 ? void 0 : _b.includes(name))
20
+ throw new Error("no allow to set this " + name);
21
+ target.$attributes = __assign(__assign({}, target.$attributes), (_a = {}, _a[name] = value, _a));
22
+ return true;
23
+ },
24
+ get: function (target, prop, value) {
25
+ var _a, _b;
26
+ try {
27
+ (0, Logger_1.LoggerMethod)(target, prop);
28
+ switch (prop) {
29
+ case 'attributes': return target["$" + prop];
30
+ case 'logger': return (_a = target.$logger) === null || _a === void 0 ? void 0 : _a.get();
31
+ case 'result': return (_b = target.$db) === null || _b === void 0 ? void 0 : _b.get('RESULT');
32
+ default: return Reflect.get(target, prop, value);
33
+ }
34
+ }
35
+ catch (e) {
36
+ throw new Error(e.message);
37
+ }
38
+ }
39
+ };
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __read = (this && this.__read) || function (o, n) {
54
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
55
+ if (!m) return o;
56
+ var i = m.call(o), r, ar = [], e;
57
+ try {
58
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
59
+ }
60
+ catch (error) { e = { error: error }; }
61
+ finally {
62
+ try {
63
+ if (r && !r.done && (m = i["return"])) m.call(i);
64
+ }
65
+ finally { if (e) throw e.error; }
66
+ }
67
+ return ar;
68
+ };
69
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
70
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
71
+ if (ar || !(i in from)) {
72
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
73
+ ar[i] = from[i];
74
+ }
75
+ }
76
+ return to.concat(ar || Array.prototype.slice.call(from));
77
+ };
78
+ var __importDefault = (this && this.__importDefault) || function (mod) {
79
+ return (mod && mod.__esModule) ? mod : { "default": mod };
80
+ };
81
+ Object.defineProperty(exports, "__esModule", { value: true });
82
+ exports.Blueprint = exports.Schema = void 0;
83
+ var Database_1 = __importDefault(require("./Database"));
84
+ var Schema = /** @class */ (function (_super) {
85
+ __extends(Schema, _super);
86
+ function Schema() {
87
+ var _this = _super !== null && _super.apply(this, arguments) || this;
88
+ _this.timeStamp = ['created_at timestamp NULL', 'updated_at timestamp NULL'];
89
+ _this.table = function (table, schemas) { return __awaiter(_this, void 0, void 0, function () {
90
+ var columns, key, data, type, attrbuites, sql, err_1;
91
+ var _a;
92
+ return __generator(this, function (_b) {
93
+ switch (_b.label) {
94
+ case 0:
95
+ _b.trys.push([0, 2, , 3]);
96
+ columns = [];
97
+ for (key in schemas) {
98
+ data = schemas[key];
99
+ 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);
101
+ }
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";
104
+ return [4 /*yield*/, this.rawQuery(sql)];
105
+ case 1:
106
+ _b.sent();
107
+ console.log("Migrats : '" + table + "' created successfully");
108
+ return [3 /*break*/, 3];
109
+ case 2:
110
+ err_1 = _b.sent();
111
+ console.log((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.replace("ER_TABLE_EXISTS_ERROR: ", ""));
112
+ return [3 /*break*/, 3];
113
+ case 3: return [2 /*return*/];
114
+ }
115
+ });
116
+ }); };
117
+ return _this;
118
+ }
119
+ return Schema;
120
+ }(Database_1.default));
121
+ exports.Schema = Schema;
122
+ var Blueprint = /** @class */ (function () {
123
+ function Blueprint() {
124
+ this.attrbuites = [];
125
+ }
126
+ Blueprint.prototype._addType = function (type) {
127
+ if (this.type != null || this.type)
128
+ return this;
129
+ this.type = type;
130
+ return this;
131
+ };
132
+ Blueprint.prototype._addAttrbuite = function (attrbuite) {
133
+ this.attrbuites = __spreadArray(__spreadArray([], __read(this.attrbuites), false), [attrbuite], false);
134
+ return this;
135
+ };
136
+ /**
137
+ *
138
+ * @Types
139
+ *
140
+ */
141
+ Blueprint.prototype.int = function () {
142
+ this._addType('INT');
143
+ return this;
144
+ };
145
+ Blueprint.prototype.tinyInt = function (n) {
146
+ if (n === void 0) { n = 1; }
147
+ this._addType("TINYINT(" + n + ")");
148
+ return this;
149
+ };
150
+ Blueprint.prototype.bigInt = function (n) {
151
+ if (n === void 0) { n = 10; }
152
+ this._addType("BIGINT(" + n + ")");
153
+ return this;
154
+ };
155
+ Blueprint.prototype.double = function () {
156
+ this._addType("DOUBLE");
157
+ return this;
158
+ };
159
+ Blueprint.prototype.float = function () {
160
+ this._addType("FLOAT");
161
+ return this;
162
+ };
163
+ Blueprint.prototype.varchar = function (n) {
164
+ if (n === void 0) { n = 100; }
165
+ if (n > 255)
166
+ n = 255;
167
+ this._addType("VARCHAR(" + n + ")");
168
+ return this;
169
+ };
170
+ Blueprint.prototype.char = function (n) {
171
+ if (n === void 0) { n = 1; }
172
+ this._addType("CHAR(" + n + ")");
173
+ return this;
174
+ };
175
+ Blueprint.prototype.longText = function () {
176
+ this._addType("LONGTEXT");
177
+ return this;
178
+ };
179
+ Blueprint.prototype.mediumText = function () {
180
+ this._addType("MEDIUMTEXT");
181
+ return this;
182
+ };
183
+ Blueprint.prototype.tinyText = function () {
184
+ this._addType("TINYTEXT");
185
+ return this;
186
+ };
187
+ Blueprint.prototype.text = function () {
188
+ this._addType("TEXT");
189
+ return this;
190
+ };
191
+ Blueprint.prototype.enum = function () {
192
+ var n = [];
193
+ for (var _i = 0; _i < arguments.length; _i++) {
194
+ n[_i] = arguments[_i];
195
+ }
196
+ this._addType("ENUM('" + n + "')");
197
+ return this;
198
+ };
199
+ Blueprint.prototype.date = function () {
200
+ this._addType("DATE");
201
+ return this;
202
+ };
203
+ Blueprint.prototype.dateTime = function () {
204
+ this._addType("DATETIME");
205
+ return this;
206
+ };
207
+ Blueprint.prototype.timestamp = function () {
208
+ this._addType("TIMESTAMP");
209
+ return this;
210
+ };
211
+ /**
212
+ *
213
+ * @Attrbuites
214
+ *
215
+ */
216
+ Blueprint.prototype.unsigned = function () {
217
+ this._addAttrbuite("UNSIGNED");
218
+ return this;
219
+ };
220
+ Blueprint.prototype.unique = function () {
221
+ this._addAttrbuite("UNIQUE");
222
+ return this;
223
+ };
224
+ Blueprint.prototype.null = function () {
225
+ this._addAttrbuite("NULL");
226
+ return this;
227
+ };
228
+ Blueprint.prototype.notNull = function () {
229
+ this._addAttrbuite("NOT NULL");
230
+ return this;
231
+ };
232
+ Blueprint.prototype.primary = function () {
233
+ this._addAttrbuite("PRIMARY KEY");
234
+ return this;
235
+ };
236
+ Blueprint.prototype.default = function (n) {
237
+ this._addAttrbuite("DEFAULT '" + n + "'");
238
+ return this;
239
+ };
240
+ Blueprint.prototype.defaultTimestamp = function () {
241
+ this._addAttrbuite("DEFAULT CURRENT_TIMESTAMP");
242
+ return this;
243
+ };
244
+ Blueprint.prototype.autoIncrement = function () {
245
+ this._addAttrbuite("AUTO_INCREMENT");
246
+ return this;
247
+ };
248
+ return Blueprint;
249
+ }());
250
+ exports.Blueprint = Blueprint;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Blueprint = exports.Schema = exports.Model = exports.DB = void 0;
7
+ var DB_1 = __importDefault(require("./DB"));
8
+ exports.DB = DB_1.default;
9
+ var Model_1 = __importDefault(require("./Model"));
10
+ exports.Model = Model_1.default;
11
+ var Schema_1 = require("./Schema");
12
+ Object.defineProperty(exports, "Schema", { enumerable: true, get: function () { return Schema_1.Schema; } });
13
+ Object.defineProperty(exports, "Blueprint", { enumerable: true, get: function () { return Schema_1.Blueprint; } });
14
+ exports.default = {
15
+ DB: DB_1.default,
16
+ Model: Model_1.default,
17
+ Schema: Schema_1.Schema,
18
+ Blueprint: Schema_1.Blueprint
19
+ };
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var constant = Object.freeze({
4
+ ID: 'ID',
5
+ SHOW: 'SHOW',
6
+ FIELDS: 'FIELDS',
7
+ COLUMNS: 'COLUMNS',
8
+ MYSQL: 'mysql',
9
+ POSTGRESQL: 'pg',
10
+ WHERE: 'WHERE',
11
+ BETWEEN: 'BETWEEN',
12
+ AND: 'AND',
13
+ IS_NULL: 'IS NULL',
14
+ IS_NOT_NULL: 'IS NOT NULL',
15
+ OR: 'OR',
16
+ LIKE: 'LIKE',
17
+ SELECT: 'SELECT',
18
+ DISTINCT: 'DISTINCT',
19
+ FROM: 'FROM',
20
+ STAR: 'STAR',
21
+ OFFSET: 'OFFSET',
22
+ GROUP_BY: 'GROUP BY',
23
+ GROUP_CONCAT: 'GROUP_CONCAT',
24
+ ORDER_BY: 'ORDER BY',
25
+ DESC: 'DESC',
26
+ ASC: 'ASC',
27
+ INNER_JOIN: 'INNER JOIN',
28
+ LEFT_JOIN: 'LEFT JOIN',
29
+ RIGHT_JOIN: 'RIGHT JOIN',
30
+ CROSS_JOIN: 'CROSS JOIN',
31
+ ON: 'ON',
32
+ LIMIT: 'LIMIT',
33
+ HAVING: 'HAVING',
34
+ COUNT: 'COUNT',
35
+ AVG: 'AVG',
36
+ SUM: 'SUM',
37
+ MAX: 'MAX',
38
+ MIN: 'MIN',
39
+ AS: 'AS',
40
+ IN: 'IN',
41
+ ALL: 'ALL',
42
+ ANY: 'ANY',
43
+ NOT_IN: 'NOT IN',
44
+ SET: 'SET',
45
+ NOT: 'NOT',
46
+ DUPLICATE: 'DUPLICATE',
47
+ KEY: 'KEY',
48
+ WHERE_NOT_EXISTS: 'WHERE NOT EXISTS',
49
+ EXISTS: 'EXISTS',
50
+ VALUES: 'VALUES',
51
+ UPDATE: 'UPDATE',
52
+ DELETE: 'DELETE',
53
+ INSERT: 'INSERT INTO',
54
+ DROP_TABLE: 'DROP TABLE',
55
+ RELATIONSHIP: {
56
+ hasOne: 'hasOne',
57
+ hasMany: 'hasMany',
58
+ belongsTo: 'belongsTo',
59
+ belongsToMany: 'belongsToMany'
60
+ },
61
+ RELATIONSHIP_CHILD: {
62
+ hasOne: 'hasOne',
63
+ hasMany: 'hasMany',
64
+ belongsTo: 'belongsTo'
65
+ },
66
+ PATTERN: {
67
+ snake_case: 'snake_case',
68
+ camelCase: 'camelCase'
69
+ }
70
+ });
71
+ exports.default = constant;
@@ -0,0 +1,297 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __values = (this && this.__values) || function(o) {
50
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
51
+ if (m) return m.call(o);
52
+ if (o && typeof o.length === "number") return {
53
+ next: function () {
54
+ if (o && i >= o.length) o = void 0;
55
+ return { value: o && o[i++], done: !o };
56
+ }
57
+ };
58
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
59
+ };
60
+ var __read = (this && this.__read) || function (o, n) {
61
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
62
+ if (!m) return o;
63
+ var i = m.call(o), r, ar = [], e;
64
+ try {
65
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
66
+ }
67
+ catch (error) { e = { error: error }; }
68
+ finally {
69
+ try {
70
+ if (r && !r.done && (m = i["return"])) m.call(i);
71
+ }
72
+ finally { if (e) throw e.error; }
73
+ }
74
+ return ar;
75
+ };
76
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
77
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
78
+ if (ar || !(i in from)) {
79
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
80
+ ar[i] = from[i];
81
+ }
82
+ }
83
+ return to.concat(ar || Array.prototype.slice.call(from));
84
+ };
85
+ var __importDefault = (this && this.__importDefault) || function (mod) {
86
+ return (mod && mod.__esModule) ? mod : { "default": mod };
87
+ };
88
+ Object.defineProperty(exports, "__esModule", { value: true });
89
+ var constant_1 = __importDefault(require("./constant"));
90
+ var connections_1 = __importDefault(require("../connections"));
91
+ var timestamp = function () {
92
+ var d = new Date();
93
+ var year = d.getFullYear();
94
+ var month = ("0" + (d.getMonth() + 1)).slice(-2);
95
+ var date = ("0" + d.getDate()).slice(-2);
96
+ var hours = ("0" + d.getHours()).slice(-2);
97
+ var minutes = ("0" + d.getMinutes()).slice(-2);
98
+ var seconds = ("0" + d.getSeconds()).slice(-2);
99
+ var now = year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds;
100
+ return now;
101
+ };
102
+ var date = function () {
103
+ var d = new Date();
104
+ var year = d.getFullYear();
105
+ var month = ("0" + (d.getMonth() + 1)).slice(-2);
106
+ var date = ("0" + d.getDate()).slice(-2);
107
+ var now = year + "-" + month + "-" + date;
108
+ return now;
109
+ };
110
+ var escape = function (str) {
111
+ try {
112
+ var check = str == null || str === true || str === false || Number.isInteger(str);
113
+ if (check)
114
+ return str;
115
+ var regx = /[`+#$&*=;'"\\|,\?~]/;
116
+ var res = str.split(regx).join("");
117
+ var regxs = ['DROP TABLE', 'UPDATE ', 'DELETE FROM ', 'OR ', 'SELECT ', 'FROM ', 'WHERE '];
118
+ for (var i in regxs) {
119
+ if (res.includes(regxs[i])) {
120
+ res = res.split(regxs[i]).join("");
121
+ }
122
+ }
123
+ return res;
124
+ }
125
+ catch (e) {
126
+ return str;
127
+ }
128
+ };
129
+ var escapeSubQuery = function (str) {
130
+ var check = str == null || str === true || str === false || Number.isInteger(str);
131
+ if (check)
132
+ return str;
133
+ var regx = /[`+#$&;"\\|\?~]/;
134
+ var res = str.split(regx).join("");
135
+ var regxs = ['DROP TABLE', 'UPDATE ', 'DELETE FROM ', 'TRUNCATE'];
136
+ for (var i in regxs) {
137
+ if (res.includes(regxs[i])) {
138
+ res = res.split(regxs[i]).join("");
139
+ }
140
+ }
141
+ return res;
142
+ };
143
+ var columnRelation = function (name) {
144
+ var _a;
145
+ var matches = (_a = name === null || name === void 0 ? void 0 : name.match(/[A-Z]/g)) !== null && _a !== void 0 ? _a : [];
146
+ if (matches.length > 1) {
147
+ matches.forEach(function (matche, i) {
148
+ if (i > 0)
149
+ name = name.replace(matche, "_" + matche.toUpperCase());
150
+ });
151
+ }
152
+ return "" + name.toLocaleLowerCase();
153
+ };
154
+ var generateUUID = function () {
155
+ var date = +new Date();
156
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
157
+ var r = Math.random() * 16;
158
+ r = (date + r) % 16 | 0;
159
+ return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
160
+ });
161
+ };
162
+ var constants = function (name) {
163
+ var e_1, _a;
164
+ if (!name)
165
+ return constant_1.default;
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()) {
168
+ var _d = __read(_c.value, 2), index = _d[0], _const = _d[1];
169
+ if (index === name)
170
+ return _const;
171
+ }
172
+ }
173
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
174
+ finally {
175
+ try {
176
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
177
+ }
178
+ finally { if (e_1) throw e_1.error; }
179
+ }
180
+ };
181
+ var tableName = function (name) {
182
+ var tb = name.replace(/([A-Z])/g, function (str) { return "_" + str.toLowerCase(); }).slice(1);
183
+ var lastString = tb.slice(-1);
184
+ var rule = ['s', 'ss', 'sh', 'ch', 'x', 'z'];
185
+ if (lastString === 'y') {
186
+ tb = tb.slice(0, -1) + 'ies';
187
+ }
188
+ else {
189
+ var checkRule = rule.indexOf(lastString) >= 0;
190
+ var word = checkRule ? 'es' : 's';
191
+ tb = tb + word;
192
+ }
193
+ return tb;
194
+ };
195
+ var covertBooleanToNumber = function (data) {
196
+ if (Object.prototype.toString.apply(data).slice(8, -1) === 'Boolean')
197
+ return +data;
198
+ return data;
199
+ };
200
+ var snakeCase = function (obj) {
201
+ try {
202
+ if (typeof (obj) !== "object")
203
+ return obj;
204
+ Object.entries(obj).forEach(function (_a) {
205
+ var _b;
206
+ var _c = __read(_a, 2), oldName = _c[0], _ = _c[1];
207
+ var newName = oldName.replace(/([A-Z])/g, function (str) { return "_" + str.toLowerCase(); });
208
+ if (newName !== oldName) {
209
+ if (obj.hasOwnProperty(oldName)) {
210
+ obj = __assign(__assign({}, obj), (_b = {}, _b[newName] = obj[oldName], _b));
211
+ delete obj[oldName];
212
+ }
213
+ }
214
+ if (typeof (obj[newName]) === "object")
215
+ obj[newName] = snakeCase(obj[newName]);
216
+ });
217
+ return obj;
218
+ }
219
+ catch (e) {
220
+ return obj;
221
+ }
222
+ };
223
+ var camelCase = function (obj) {
224
+ try {
225
+ if (typeof (obj) !== "object")
226
+ return obj;
227
+ Object.entries(obj).forEach(function (_a) {
228
+ var _b;
229
+ var _c = __read(_a, 2), oldName = _c[0], _ = _c[1];
230
+ var newName = oldName.replace(/(.(\_|-|\s)+.)/g, function (str) { return str[0] + (str[str.length - 1].toUpperCase()); });
231
+ if (newName !== oldName) {
232
+ if (obj.hasOwnProperty(oldName)) {
233
+ obj = __assign(__assign({}, obj), (_b = {}, _b[newName] = obj[oldName], _b));
234
+ delete obj[oldName];
235
+ }
236
+ }
237
+ if (typeof (obj[newName]) === "object")
238
+ obj[newName] = camelCase(obj[newName]);
239
+ });
240
+ return obj;
241
+ }
242
+ catch (e) {
243
+ return obj;
244
+ }
245
+ };
246
+ var consoleDebug = function (message) {
247
+ if (message == null)
248
+ return;
249
+ console.log("SQL Statement: \u001B[33m" + message + " \u001B[0m ");
250
+ };
251
+ var connection = function () { return __awaiter(void 0, void 0, void 0, function () {
252
+ return __generator(this, function (_a) {
253
+ switch (_a.label) {
254
+ case 0: return [4 /*yield*/, connections_1.default];
255
+ case 1: return [2 /*return*/, _a.sent()];
256
+ }
257
+ });
258
+ }); };
259
+ var faker = function (value) {
260
+ if (!value.search('timestamp'))
261
+ return timestamp();
262
+ if (!value.search('datetime'))
263
+ return timestamp();
264
+ if (!value.search('date'))
265
+ return date();
266
+ if (!value.search('tinyint'))
267
+ return [true, false][Math.round(Math.random())];
268
+ if (!value.search('boolean'))
269
+ return [true, false][Math.round(Math.random())];
270
+ if (!value.search('longtext'))
271
+ return __spreadArray([], __read(Array(50)), false).map(function () { return Math.random().toString(36).substring(7); }).join('');
272
+ if (!value.search('int'))
273
+ return Math.floor(Math.random() * 1000);
274
+ if (!value.search('float'))
275
+ return (Math.random() * 100).toFixed(2);
276
+ if (!value.search('double'))
277
+ return (Math.random() * 100).toFixed(2);
278
+ if (!value.search('varchar'))
279
+ return Buffer.from(Math.random().toString(36).substring(7)).toString('base64');
280
+ return 'fake data';
281
+ };
282
+ exports.default = {
283
+ consoleDebug: consoleDebug,
284
+ tableName: tableName,
285
+ faker: faker,
286
+ connection: connection,
287
+ columnRelation: columnRelation,
288
+ timestamp: timestamp,
289
+ date: date,
290
+ escape: escape,
291
+ escapeSubQuery: escapeSubQuery,
292
+ generateUUID: generateUUID,
293
+ constants: constants,
294
+ covertBooleanToNumber: covertBooleanToNumber,
295
+ snakeCase: snakeCase,
296
+ camelCase: camelCase
297
+ };