tspace-mysql 1.1.2 → 1.1.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/dist/cli/index.js +23 -24
- package/dist/cli/migrate/make.js +18 -41
- package/dist/cli/models/make.js +18 -18
- package/dist/cli/models/model.js +27 -2
- package/dist/cli/tables/make.js +10 -10
- package/dist/cli/tables/table.js +22 -2
- package/dist/lib/config/env.d.ts +6 -0
- package/dist/lib/config/env.js +16 -10
- package/dist/lib/connection/index.d.ts +29 -8
- package/dist/lib/connection/index.js +111 -55
- package/dist/lib/constants/index.js +7 -5
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +2 -2
- package/dist/lib/tspace/AbstractDB.js +3 -23
- package/dist/lib/tspace/AbstractDatabase.d.ts +9 -4
- package/dist/lib/tspace/AbstractDatabase.js +28 -31
- package/dist/lib/tspace/AbstractModel.d.ts +30 -16
- package/dist/lib/tspace/AbstractModel.js +3 -23
- package/dist/lib/tspace/Blueprint.d.ts +92 -21
- package/dist/lib/tspace/Blueprint.js +171 -140
- package/dist/lib/tspace/DB.d.ts +27 -4
- package/dist/lib/tspace/DB.js +66 -158
- package/dist/lib/tspace/Database.d.ts +100 -51
- package/dist/lib/tspace/Database.js +1335 -1911
- package/dist/lib/tspace/Interface.d.ts +8 -8
- package/dist/lib/tspace/Logger.js +19 -19
- package/dist/lib/tspace/Model.d.ts +168 -132
- package/dist/lib/tspace/Model.js +1467 -2081
- package/dist/lib/tspace/ProxyHandler.js +15 -26
- package/dist/lib/tspace/Schema.js +25 -117
- package/dist/lib/tspace/index.js +4 -4
- package/dist/lib/utils/index.d.ts +4 -3
- package/dist/lib/utils/index.js +87 -112
- package/package.json +1 -1
|
@@ -1,41 +1,30 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.proxyHandler = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
set:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
const Logger_1 = require("./Logger");
|
|
5
|
+
const proxyHandler = {
|
|
6
|
+
set: (self, name, value) => {
|
|
7
|
+
if (self.$setters?.includes(name))
|
|
8
|
+
throw new Error(`no allow to set this ${name}`);
|
|
9
|
+
self.$attributes = {
|
|
10
|
+
...self.$attributes,
|
|
11
|
+
[name]: value
|
|
12
|
+
};
|
|
23
13
|
return true;
|
|
24
14
|
},
|
|
25
|
-
get:
|
|
26
|
-
var _a, _b, _c, _d;
|
|
15
|
+
get: (self, prop, value) => {
|
|
27
16
|
try {
|
|
28
17
|
new Logger_1.Logger(self, prop);
|
|
29
18
|
switch (prop) {
|
|
30
|
-
case 'tableName': return
|
|
31
|
-
case 'attributes': return self[
|
|
32
|
-
case 'logger': return
|
|
33
|
-
case 'result': return
|
|
19
|
+
case 'tableName': return self.$db?.get('TABLE_NAME')?.replace(/`/g, '');
|
|
20
|
+
case 'attributes': return self[`$${prop}`];
|
|
21
|
+
case 'logger': return self.$logger?.get();
|
|
22
|
+
case 'result': return self.$db?.get('RESULT');
|
|
34
23
|
default: return Reflect.get(self, prop, value);
|
|
35
24
|
}
|
|
36
25
|
}
|
|
37
26
|
catch (e) {
|
|
38
|
-
throw new Error(e
|
|
27
|
+
throw new Error(e?.message);
|
|
39
28
|
}
|
|
40
29
|
}
|
|
41
30
|
};
|
|
@@ -1,123 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 {
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Schema = void 0;
|
|
4
|
+
const Database_1 = require("./Database");
|
|
5
|
+
class Schema extends Database_1.Database {
|
|
6
|
+
table = async (table, schemas) => {
|
|
62
7
|
try {
|
|
63
|
-
|
|
8
|
+
let columns = [];
|
|
9
|
+
for (const key in schemas) {
|
|
10
|
+
const data = schemas[key];
|
|
11
|
+
const { type, attrbuites } = data;
|
|
12
|
+
columns = [
|
|
13
|
+
...columns,
|
|
14
|
+
`${key} ${type} ${attrbuites?.join(' ')}`
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
const sql = [
|
|
18
|
+
`CREATE TABLE IF NOT EXISTS`,
|
|
19
|
+
`${table} (${columns?.join(',')})`,
|
|
20
|
+
`ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8`
|
|
21
|
+
].join(' ');
|
|
22
|
+
await this.rawQuery(sql);
|
|
23
|
+
console.log(`Migrats : '${table}' created successfully`);
|
|
64
24
|
}
|
|
65
|
-
|
|
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];
|
|
25
|
+
catch (err) {
|
|
26
|
+
console.log(err.message?.replace("ER_TABLE_EXISTS_ERROR: ", ""));
|
|
74
27
|
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
};
|
|
78
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
79
|
-
exports.Schema = void 0;
|
|
80
|
-
var Database_1 = require("./Database");
|
|
81
|
-
var Schema = /** @class */ (function (_super) {
|
|
82
|
-
__extends(Schema, _super);
|
|
83
|
-
function Schema() {
|
|
84
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
85
|
-
_this.table = function (table, schemas) { return __awaiter(_this, void 0, void 0, function () {
|
|
86
|
-
var columns, key, data, type, attrbuites, sql, err_1;
|
|
87
|
-
var _a;
|
|
88
|
-
return __generator(this, function (_b) {
|
|
89
|
-
switch (_b.label) {
|
|
90
|
-
case 0:
|
|
91
|
-
_b.trys.push([0, 2, , 3]);
|
|
92
|
-
columns = [];
|
|
93
|
-
for (key in schemas) {
|
|
94
|
-
data = schemas[key];
|
|
95
|
-
type = data.type, attrbuites = data.attrbuites;
|
|
96
|
-
columns = __spreadArray(__spreadArray([], __read(columns), false), [
|
|
97
|
-
"".concat(key, " ").concat(type, " ").concat(attrbuites === null || attrbuites === void 0 ? void 0 : attrbuites.join(' '))
|
|
98
|
-
], false);
|
|
99
|
-
}
|
|
100
|
-
sql = [
|
|
101
|
-
"CREATE TABLE IF NOT EXISTS",
|
|
102
|
-
"".concat(table, " (").concat(columns === null || columns === void 0 ? void 0 : columns.join(','), ")"),
|
|
103
|
-
"ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8"
|
|
104
|
-
].join(' ');
|
|
105
|
-
return [4 /*yield*/, this.rawQuery(sql)];
|
|
106
|
-
case 1:
|
|
107
|
-
_b.sent();
|
|
108
|
-
console.log("Migrats : '".concat(table, "' created successfully"));
|
|
109
|
-
return [3 /*break*/, 3];
|
|
110
|
-
case 2:
|
|
111
|
-
err_1 = _b.sent();
|
|
112
|
-
console.log((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.replace("ER_TABLE_EXISTS_ERROR: ", ""));
|
|
113
|
-
return [3 /*break*/, 3];
|
|
114
|
-
case 3: return [2 /*return*/];
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}); };
|
|
118
|
-
return _this;
|
|
119
|
-
}
|
|
120
|
-
return Schema;
|
|
121
|
-
}(Database_1.Database));
|
|
28
|
+
};
|
|
29
|
+
}
|
|
122
30
|
exports.Schema = Schema;
|
|
123
31
|
exports.default = Schema;
|
package/dist/lib/tspace/index.js
CHANGED
|
@@ -4,13 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Blueprint = exports.Schema = exports.Model = exports.DB = void 0;
|
|
7
|
-
|
|
7
|
+
const DB_1 = __importDefault(require("./DB"));
|
|
8
8
|
exports.DB = DB_1.default;
|
|
9
|
-
|
|
9
|
+
const Model_1 = __importDefault(require("./Model"));
|
|
10
10
|
exports.Model = Model_1.default;
|
|
11
|
-
|
|
11
|
+
const Schema_1 = __importDefault(require("./Schema"));
|
|
12
12
|
exports.Schema = Schema_1.default;
|
|
13
|
-
|
|
13
|
+
const Blueprint_1 = __importDefault(require("./Blueprint"));
|
|
14
14
|
exports.Blueprint = Blueprint_1.default;
|
|
15
15
|
exports.default = {
|
|
16
16
|
DB: DB_1.default,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
consoleDebug: (debug?: string
|
|
1
|
+
declare const utils: {
|
|
2
|
+
consoleDebug: (debug?: string) => void;
|
|
3
3
|
tableName: (name: string) => string;
|
|
4
4
|
faker: (value: string) => string | number | boolean;
|
|
5
5
|
columnRelation: (name: string) => string;
|
|
@@ -12,4 +12,5 @@ declare const _default: {
|
|
|
12
12
|
snakeCase: (obj: any) => any;
|
|
13
13
|
camelCase: (obj: any) => any;
|
|
14
14
|
};
|
|
15
|
-
export
|
|
15
|
+
export { utils };
|
|
16
|
+
export default utils;
|
package/dist/lib/utils/index.js
CHANGED
|
@@ -1,69 +1,43 @@
|
|
|
1
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 __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
3
|
+
exports.utils = void 0;
|
|
4
|
+
const timestamp = () => {
|
|
5
|
+
const d = new Date();
|
|
6
|
+
const year = d.getFullYear();
|
|
7
|
+
const month = `0${(d.getMonth() + 1)}`.slice(-2);
|
|
8
|
+
const date = `0${(d.getDate())}`.slice(-2);
|
|
9
|
+
const hours = `0${(d.getHours())}`.slice(-2);
|
|
10
|
+
const minutes = `0${(d.getMinutes())}`.slice(-2);
|
|
11
|
+
const seconds = `0${(d.getSeconds())}`.slice(-2);
|
|
12
|
+
const ymd = `${[
|
|
13
|
+
year,
|
|
14
|
+
month,
|
|
15
|
+
date
|
|
16
|
+
].join('-')}`;
|
|
17
|
+
const his = `${[
|
|
18
|
+
hours,
|
|
19
|
+
minutes,
|
|
20
|
+
seconds
|
|
21
|
+
].join(':')}`;
|
|
22
|
+
return `${ymd} ${his}`;
|
|
23
|
+
};
|
|
24
|
+
const date = () => {
|
|
25
|
+
const d = new Date();
|
|
26
|
+
const year = d.getFullYear();
|
|
27
|
+
const month = ("0" + (d.getMonth() + 1)).slice(-2);
|
|
28
|
+
const date = ("0" + d.getDate()).slice(-2);
|
|
29
|
+
const now = `${year}-${month}-${date}`;
|
|
48
30
|
return now;
|
|
49
31
|
};
|
|
50
|
-
|
|
51
|
-
var d = new Date();
|
|
52
|
-
var year = d.getFullYear();
|
|
53
|
-
var month = ("0" + (d.getMonth() + 1)).slice(-2);
|
|
54
|
-
var date = ("0" + d.getDate()).slice(-2);
|
|
55
|
-
var now = "".concat(year, "-").concat(month, "-").concat(date);
|
|
56
|
-
return now;
|
|
57
|
-
};
|
|
58
|
-
var escape = function (str) {
|
|
32
|
+
const escape = (str) => {
|
|
59
33
|
try {
|
|
60
|
-
|
|
34
|
+
const check = str == null || str === true || str === false || Number.isInteger(str);
|
|
61
35
|
if (check)
|
|
62
36
|
return str;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
for (
|
|
37
|
+
const regx = /[`+#$&*=;\\|,\?~]/;
|
|
38
|
+
let res = str.split(regx).join("");
|
|
39
|
+
const regxs = ['DROP TABLE', 'UPDATE ', 'DELETE FROM ', 'OR ', 'SELECT ', 'FROM ', 'WHERE '];
|
|
40
|
+
for (let i in regxs) {
|
|
67
41
|
if (res.includes(regxs[i])) {
|
|
68
42
|
res = res.split(regxs[i]).join("");
|
|
69
43
|
}
|
|
@@ -74,69 +48,68 @@ var escape = function (str) {
|
|
|
74
48
|
return str;
|
|
75
49
|
}
|
|
76
50
|
};
|
|
77
|
-
|
|
78
|
-
|
|
51
|
+
const escapeSubQuery = (str) => {
|
|
52
|
+
const check = str == null || str === true || str === false || Number.isInteger(str);
|
|
79
53
|
if (check)
|
|
80
54
|
return str;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
for (
|
|
55
|
+
const regx = /[`+#$&;\\|\?~]/;
|
|
56
|
+
let res = str.split(regx).join("");
|
|
57
|
+
const regxs = ['DROP TABLE', 'UPDATE ', 'DELETE FROM ', 'TRUNCATE'];
|
|
58
|
+
for (let i in regxs) {
|
|
85
59
|
if (res.includes(regxs[i])) {
|
|
86
60
|
res = res.split(regxs[i]).join("");
|
|
87
61
|
}
|
|
88
62
|
}
|
|
89
63
|
return res;
|
|
90
64
|
};
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
var matches = (_a = name === null || name === void 0 ? void 0 : name.match(/[A-Z]/g)) !== null && _a !== void 0 ? _a : [];
|
|
65
|
+
const columnRelation = (name) => {
|
|
66
|
+
const matches = name?.match(/[A-Z]/g) ?? [];
|
|
94
67
|
if (matches.length > 1) {
|
|
95
|
-
matches.forEach(
|
|
68
|
+
matches.forEach((matche, i) => {
|
|
96
69
|
if (i > 0)
|
|
97
|
-
name = name.replace(matche,
|
|
70
|
+
name = name.replace(matche, `_${matche.toUpperCase()}`);
|
|
98
71
|
});
|
|
99
72
|
}
|
|
100
|
-
return
|
|
73
|
+
return `${name.toLocaleLowerCase()}`;
|
|
101
74
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
|
|
105
|
-
|
|
75
|
+
const generateUUID = () => {
|
|
76
|
+
const date = +new Date();
|
|
77
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
78
|
+
let r = Math.random() * 16;
|
|
106
79
|
r = (date + r) % 16 | 0;
|
|
107
80
|
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
|
|
108
81
|
});
|
|
109
82
|
};
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
83
|
+
const tableName = (name) => {
|
|
84
|
+
let tb = name.replace(/([A-Z])/g, (str) => "_" + str.toLowerCase()).slice(1);
|
|
85
|
+
const lastString = tb.slice(-1);
|
|
86
|
+
const rule = ['s', 'ss', 'sh', 'ch', 'x', 'z'];
|
|
114
87
|
if (lastString === 'y') {
|
|
115
88
|
tb = tb.slice(0, -1) + 'ies';
|
|
116
89
|
}
|
|
117
90
|
else {
|
|
118
|
-
|
|
119
|
-
|
|
91
|
+
const checkRule = rule.indexOf(lastString) >= 0;
|
|
92
|
+
const word = checkRule ? 'es' : 's';
|
|
120
93
|
tb = tb + word;
|
|
121
94
|
}
|
|
122
95
|
return tb;
|
|
123
96
|
};
|
|
124
|
-
|
|
97
|
+
const covertBooleanToNumber = (data) => {
|
|
125
98
|
if (Object.prototype.toString.apply(data).slice(8, -1) === 'Boolean')
|
|
126
99
|
return +data;
|
|
127
100
|
return data;
|
|
128
101
|
};
|
|
129
|
-
|
|
102
|
+
const snakeCase = (obj) => {
|
|
130
103
|
try {
|
|
131
104
|
if (typeof (obj) !== "object")
|
|
132
105
|
return obj;
|
|
133
|
-
Object.entries(obj).forEach(
|
|
134
|
-
|
|
135
|
-
var _c = __read(_a, 2), oldName = _c[0], _ = _c[1];
|
|
136
|
-
var newName = oldName.replace(/([A-Z])/g, function (str) { return "_".concat(str.toLowerCase()); });
|
|
106
|
+
Object.entries(obj).forEach(([oldName, _]) => {
|
|
107
|
+
const newName = oldName.replace(/([A-Z])/g, (str) => `_${str.toLowerCase()}`);
|
|
137
108
|
if (newName !== oldName) {
|
|
138
109
|
if (obj.hasOwnProperty(oldName)) {
|
|
139
|
-
obj =
|
|
110
|
+
obj = { ...obj,
|
|
111
|
+
[newName]: obj[oldName]
|
|
112
|
+
};
|
|
140
113
|
delete obj[oldName];
|
|
141
114
|
}
|
|
142
115
|
}
|
|
@@ -149,17 +122,17 @@ var snakeCase = function (obj) {
|
|
|
149
122
|
return obj;
|
|
150
123
|
}
|
|
151
124
|
};
|
|
152
|
-
|
|
125
|
+
const camelCase = (obj) => {
|
|
153
126
|
try {
|
|
154
127
|
if (typeof (obj) !== "object")
|
|
155
128
|
return obj;
|
|
156
|
-
Object.entries(obj).forEach(
|
|
157
|
-
|
|
158
|
-
var _c = __read(_a, 2), oldName = _c[0], _ = _c[1];
|
|
159
|
-
var newName = oldName.replace(/(.(\_|-|\s)+.)/g, function (str) { return str[0] + (str[str.length - 1].toUpperCase()); });
|
|
129
|
+
Object.entries(obj).forEach(([oldName, _]) => {
|
|
130
|
+
const newName = oldName.replace(/(.(\_|-|\s)+.)/g, (str) => str[0] + (str[str.length - 1].toUpperCase()));
|
|
160
131
|
if (newName !== oldName) {
|
|
161
132
|
if (obj.hasOwnProperty(oldName)) {
|
|
162
|
-
obj =
|
|
133
|
+
obj = { ...obj,
|
|
134
|
+
[newName]: obj[oldName]
|
|
135
|
+
};
|
|
163
136
|
delete obj[oldName];
|
|
164
137
|
}
|
|
165
138
|
}
|
|
@@ -172,12 +145,12 @@ var camelCase = function (obj) {
|
|
|
172
145
|
return obj;
|
|
173
146
|
}
|
|
174
147
|
};
|
|
175
|
-
|
|
148
|
+
const consoleDebug = (debug) => {
|
|
176
149
|
if (debug == null)
|
|
177
150
|
return;
|
|
178
|
-
console.log(
|
|
151
|
+
console.log(`\nSQL Statement: \x1b[33m${debug} \x1b[0m`);
|
|
179
152
|
};
|
|
180
|
-
|
|
153
|
+
const faker = (value) => {
|
|
181
154
|
if (!value.search('timestamp'))
|
|
182
155
|
return timestamp();
|
|
183
156
|
if (!value.search('datetime'))
|
|
@@ -189,7 +162,7 @@ var faker = function (value) {
|
|
|
189
162
|
if (!value.search('boolean'))
|
|
190
163
|
return [true, false][Math.round(Math.random())];
|
|
191
164
|
if (!value.search('longtext'))
|
|
192
|
-
return
|
|
165
|
+
return [...Array(50)].map(() => Math.random().toString(36).substring(7)).join('');
|
|
193
166
|
if (!value.search('int'))
|
|
194
167
|
return Math.floor(Math.random() * 1000);
|
|
195
168
|
if (!value.search('float'))
|
|
@@ -200,17 +173,19 @@ var faker = function (value) {
|
|
|
200
173
|
return Buffer.from(Math.random().toString(36).substring(7)).toString('base64');
|
|
201
174
|
return 'fake data';
|
|
202
175
|
};
|
|
203
|
-
|
|
204
|
-
consoleDebug
|
|
205
|
-
tableName
|
|
206
|
-
faker
|
|
207
|
-
columnRelation
|
|
208
|
-
timestamp
|
|
209
|
-
date
|
|
210
|
-
escape
|
|
211
|
-
escapeSubQuery
|
|
212
|
-
generateUUID
|
|
213
|
-
covertBooleanToNumber
|
|
214
|
-
snakeCase
|
|
215
|
-
camelCase
|
|
216
|
-
};
|
|
176
|
+
const utils = {
|
|
177
|
+
consoleDebug,
|
|
178
|
+
tableName,
|
|
179
|
+
faker,
|
|
180
|
+
columnRelation,
|
|
181
|
+
timestamp,
|
|
182
|
+
date,
|
|
183
|
+
escape,
|
|
184
|
+
escapeSubQuery,
|
|
185
|
+
generateUUID,
|
|
186
|
+
covertBooleanToNumber,
|
|
187
|
+
snakeCase,
|
|
188
|
+
camelCase
|
|
189
|
+
};
|
|
190
|
+
exports.utils = utils;
|
|
191
|
+
exports.default = utils;
|