@klapeks/micro-db-utils 0.0.3 → 0.0.5
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.
|
@@ -104,7 +104,8 @@ var MySQLMigrations = /** @class */ (function () {
|
|
|
104
104
|
migrationRecords_1 = _b.sent();
|
|
105
105
|
runnedMigrationsAmount_1 = 0;
|
|
106
106
|
runTableMigration = function (table) { return __awaiter(_this, void 0, void 0, function () {
|
|
107
|
-
var todoMigrations, tableInfo, lastMigrationDate, lastRealMigration, _i, todoMigrations_1, migration, migrationName, sqls, _a, sqls_1, sql, sql;
|
|
107
|
+
var todoMigrations, tableInfo, lastMigrationDate, lastRealMigration, _local_runSQL, _i, todoMigrations_1, migration, migrationName, sqls, _a, sqls_1, sql, sql;
|
|
108
|
+
var _this = this;
|
|
108
109
|
var _b, _c;
|
|
109
110
|
return __generator(this, function (_d) {
|
|
110
111
|
switch (_d.label) {
|
|
@@ -125,6 +126,30 @@ var MySQLMigrations = /** @class */ (function () {
|
|
|
125
126
|
case 3: return [2 /*return*/];
|
|
126
127
|
case 4:
|
|
127
128
|
lastRealMigration = (_c = migrationRecords_1 === null || migrationRecords_1 === void 0 ? void 0 : migrationRecords_1.find(function (r) { return r.table == table; })) === null || _c === void 0 ? void 0 : _c.lastMigrationTime;
|
|
129
|
+
_local_runSQL = function (sql) { return __awaiter(_this, void 0, void 0, function () {
|
|
130
|
+
return __generator(this, function (_a) {
|
|
131
|
+
switch (_a.label) {
|
|
132
|
+
case 0:
|
|
133
|
+
if (!sql.toLowerCase().startsWith("alter table")) return [3 /*break*/, 2];
|
|
134
|
+
// log error if error
|
|
135
|
+
return [4 /*yield*/, mysqlInstance_1.runSQL(sql).catch(function (err) {
|
|
136
|
+
logger.error("Error while alter table:", err);
|
|
137
|
+
})];
|
|
138
|
+
case 1:
|
|
139
|
+
// log error if error
|
|
140
|
+
_a.sent();
|
|
141
|
+
return [3 /*break*/, 4];
|
|
142
|
+
case 2:
|
|
143
|
+
// throw error if error
|
|
144
|
+
return [4 /*yield*/, mysqlInstance_1.runSQL(sql)];
|
|
145
|
+
case 3:
|
|
146
|
+
// throw error if error
|
|
147
|
+
_a.sent();
|
|
148
|
+
_a.label = 4;
|
|
149
|
+
case 4: return [2 /*return*/];
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}); };
|
|
128
153
|
_i = 0, todoMigrations_1 = todoMigrations;
|
|
129
154
|
_d.label = 5;
|
|
130
155
|
case 5:
|
|
@@ -147,7 +172,7 @@ var MySQLMigrations = /** @class */ (function () {
|
|
|
147
172
|
case 6:
|
|
148
173
|
if (!(_a < sqls_1.length)) return [3 /*break*/, 9];
|
|
149
174
|
sql = sqls_1[_a];
|
|
150
|
-
return [4 /*yield*/,
|
|
175
|
+
return [4 /*yield*/, _local_runSQL(sql)];
|
|
151
176
|
case 7:
|
|
152
177
|
_d.sent();
|
|
153
178
|
_d.label = 8;
|
|
@@ -158,7 +183,7 @@ var MySQLMigrations = /** @class */ (function () {
|
|
|
158
183
|
case 10:
|
|
159
184
|
sql = utils_1.utils.replaceAll(migration.sql, "%{table_name}", table);
|
|
160
185
|
logger.log(runnedMigrationsAmount_1, "| Migration will be runned:", migrationName, '|\n' + utils_1.terminalColors.cyan, sql.trim());
|
|
161
|
-
return [4 /*yield*/,
|
|
186
|
+
return [4 /*yield*/, _local_runSQL(sql)];
|
|
162
187
|
case 11:
|
|
163
188
|
_d.sent();
|
|
164
189
|
_d.label = 12;
|
|
@@ -91,10 +91,10 @@ var AbstractSelectHandler = /** @class */ (function () {
|
|
|
91
91
|
var _a;
|
|
92
92
|
return __awaiter(this, void 0, void 0, function () {
|
|
93
93
|
var stat, time, response, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
94
|
-
var _p;
|
|
94
|
+
var _p, _q;
|
|
95
95
|
var _this = this;
|
|
96
|
-
return __generator(this, function (
|
|
97
|
-
switch (
|
|
96
|
+
return __generator(this, function (_r) {
|
|
97
|
+
switch (_r.label) {
|
|
98
98
|
case 0:
|
|
99
99
|
stat = function (fromDate, time) { return __awaiter(_this, void 0, void 0, function () {
|
|
100
100
|
var isoDate, sum;
|
|
@@ -123,56 +123,60 @@ var AbstractSelectHandler = /** @class */ (function () {
|
|
|
123
123
|
};
|
|
124
124
|
return [4 /*yield*/, this.getTotal()];
|
|
125
125
|
case 1:
|
|
126
|
-
response = (_p.count =
|
|
126
|
+
response = (_p.count = _r.sent(),
|
|
127
127
|
_p);
|
|
128
128
|
_b = response;
|
|
129
|
-
|
|
129
|
+
_q = {
|
|
130
|
+
from: new Date(0)
|
|
131
|
+
};
|
|
132
|
+
return [4 /*yield*/, this.runSQL_One("\n SELECT SUM(".concat(sumField, ") as sum\n FROM ").concat(this.getTableName(), "\n ").concat(strWhere ? ("WHERE " + strWhere) : '', "\n "))];
|
|
130
133
|
case 2:
|
|
131
|
-
_b.total = (_a = (
|
|
134
|
+
_b.total = (_q.sum = (_a = (_r.sent())) === null || _a === void 0 ? void 0 : _a.sum,
|
|
135
|
+
_q);
|
|
132
136
|
_c = response;
|
|
133
137
|
return [4 /*yield*/, stat(new Date())];
|
|
134
138
|
case 3:
|
|
135
|
-
_c.thisDay =
|
|
139
|
+
_c.thisDay = _r.sent();
|
|
136
140
|
_d = response;
|
|
137
141
|
return [4 /*yield*/, stat(function (d) { return d.setDate(d.getDate() - (d.getDay() || 7) + 1); })];
|
|
138
142
|
case 4:
|
|
139
|
-
_d.thisWeek =
|
|
143
|
+
_d.thisWeek = _r.sent();
|
|
140
144
|
_e = response;
|
|
141
145
|
return [4 /*yield*/, stat(function (d) { return d.setDate(1); })];
|
|
142
146
|
case 5:
|
|
143
|
-
_e.thisMonth =
|
|
147
|
+
_e.thisMonth = _r.sent();
|
|
144
148
|
_f = response;
|
|
145
149
|
return [4 /*yield*/, stat(function (d) { d.setMonth(0); d.setDate(1); })];
|
|
146
150
|
case 6:
|
|
147
|
-
_f.thisYear =
|
|
151
|
+
_f.thisYear = _r.sent();
|
|
148
152
|
_g = response;
|
|
149
153
|
return [4 /*yield*/, stat(function (d) { return d.setDate(d.getDate() - 1); }, time)];
|
|
150
154
|
case 7:
|
|
151
|
-
_g.past24hours =
|
|
155
|
+
_g.past24hours = _r.sent();
|
|
152
156
|
_h = response;
|
|
153
157
|
return [4 /*yield*/, stat(function (d) { return d.setDate(d.getDate() - 2); })];
|
|
154
158
|
case 8:
|
|
155
|
-
_h.past3days =
|
|
159
|
+
_h.past3days = _r.sent();
|
|
156
160
|
_j = response;
|
|
157
161
|
return [4 /*yield*/, stat(function (d) { return d.setDate(d.getDate() - 6); })];
|
|
158
162
|
case 9:
|
|
159
|
-
_j.past7days =
|
|
163
|
+
_j.past7days = _r.sent();
|
|
160
164
|
_k = response;
|
|
161
165
|
return [4 /*yield*/, stat(function (d) { return d.setDate(d.getDate() - 13); })];
|
|
162
166
|
case 10:
|
|
163
|
-
_k.past14days =
|
|
167
|
+
_k.past14days = _r.sent();
|
|
164
168
|
_l = response;
|
|
165
169
|
return [4 /*yield*/, stat(function (d) { return d.setDate(d.getDate() - 29); })];
|
|
166
170
|
case 11:
|
|
167
|
-
_l.past30days =
|
|
171
|
+
_l.past30days = _r.sent();
|
|
168
172
|
_m = response;
|
|
169
173
|
return [4 /*yield*/, stat(function (d) { return d.setMonth(d.getMonth() - 6); })];
|
|
170
174
|
case 12:
|
|
171
|
-
_m.past6months =
|
|
175
|
+
_m.past6months = _r.sent();
|
|
172
176
|
_o = response;
|
|
173
177
|
return [4 /*yield*/, stat(function (d) { return d.setMonth(d.getMonth() - 12); })];
|
|
174
178
|
case 13:
|
|
175
|
-
_o.past12months =
|
|
179
|
+
_o.past12months = _r.sent();
|
|
176
180
|
return [2 /*return*/, response];
|
|
177
181
|
}
|
|
178
182
|
});
|