exodus-framework 2.1.1017 → 2.1.1018
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/lib/utils/database.d.ts.map +1 -1
- package/lib/utils/database.js +43 -14
- package/package.json +1 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGjE,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEzF,eAAO,MAAM,MAAM,WASjB,CAAC;AAqIH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,GACnF,YAAY,CAAC,CAAC,CAAC,CAqDjB;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,EAClC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,iBAalD"}
|
package/lib/utils/database.js
CHANGED
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.InsertIndexes = InsertIndexes;
|
7
7
|
exports.mainDb = void 0;
|
8
8
|
exports.processFilters = processFilters;
|
9
|
+
var _dateFns = require("date-fns");
|
9
10
|
var _sequelize = require("sequelize");
|
10
11
|
var _core = _interopRequireDefault(require("../app/core"));
|
11
12
|
var _error = require("../app/error");
|
12
|
-
var _dateFns = require("date-fns");
|
13
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
14
14
|
const mainDb = exports.mainDb = new _sequelize.Sequelize({
|
15
15
|
database: _core.default.settings.getDatabase().main.database,
|
@@ -23,7 +23,7 @@ const mainDb = exports.mainDb = new _sequelize.Sequelize({
|
|
23
23
|
timezone: '-03:00',
|
24
24
|
logging: _core.default.settings.getDatabase().service.log
|
25
25
|
});
|
26
|
-
function processCondition(cond) {
|
26
|
+
function processCondition(cond, fieldName) {
|
27
27
|
if ('or' in cond) {
|
28
28
|
return {
|
29
29
|
[_sequelize.Op.or]: cond.or.map(subCond => processCondition(subCond))
|
@@ -51,12 +51,32 @@ function processCondition(cond) {
|
|
51
51
|
simpleWhere[_sequelize.Op.notBetween] = cond.type === 'DATE' ? cond.notBetween.map(d => new Date(d)) : cond.notBetween;
|
52
52
|
}
|
53
53
|
if (cond.like !== undefined) {
|
54
|
-
const
|
55
|
-
|
54
|
+
const value = cond.type === 'DATE' ? new Date(cond.like) : cond.like;
|
55
|
+
if (cond.caseInsensitive && fieldName) {
|
56
|
+
const dialect = _core.default.settings.getDatabase().main.dialect;
|
57
|
+
if (dialect === 'postgres') {
|
58
|
+
simpleWhere[_sequelize.Op.iLike] = value;
|
59
|
+
} else {
|
60
|
+
// Para MariaDB/MySQL, usamos Sequelize.where com função LOWER
|
61
|
+
return _sequelize.Sequelize.where(_sequelize.Sequelize.fn('LOWER', _sequelize.Sequelize.col(fieldName)), _sequelize.Op.like, `${value}`.toLowerCase());
|
62
|
+
}
|
63
|
+
} else {
|
64
|
+
simpleWhere[_sequelize.Op.like] = value;
|
65
|
+
}
|
56
66
|
}
|
57
67
|
if (cond.notLike !== undefined) {
|
58
|
-
const
|
59
|
-
|
68
|
+
const value = cond.type === 'DATE' ? new Date(cond.notLike) : cond.notLike;
|
69
|
+
if (cond.caseInsensitive && fieldName) {
|
70
|
+
const dialect = _core.default.settings.getDatabase().main.dialect;
|
71
|
+
if (dialect === 'postgres') {
|
72
|
+
simpleWhere[_sequelize.Op.notILike] = value;
|
73
|
+
} else {
|
74
|
+
// Para MariaDB/MySQL, usamos Sequelize.where com função LOWER
|
75
|
+
return _sequelize.Sequelize.where(_sequelize.Sequelize.fn('LOWER', _sequelize.Sequelize.col(fieldName)), _sequelize.Op.notLike, `${value}`.toLowerCase());
|
76
|
+
}
|
77
|
+
} else {
|
78
|
+
simpleWhere[_sequelize.Op.notLike] = value;
|
79
|
+
}
|
60
80
|
}
|
61
81
|
if (cond.in !== undefined) {
|
62
82
|
simpleWhere[_sequelize.Op.in] = cond.type === 'DATE' ? cond.in.map(d => new Date(d)) : cond.in;
|
@@ -131,7 +151,7 @@ function processFilters(filters) {
|
|
131
151
|
for (const c of condition) {
|
132
152
|
const [[key, value]] = Object.entries(c);
|
133
153
|
t.push({
|
134
|
-
[key]: processCondition(value)
|
154
|
+
[key]: processCondition(value, key)
|
135
155
|
});
|
136
156
|
}
|
137
157
|
if (!where[logicalOp]) {
|
@@ -148,14 +168,23 @@ function processFilters(filters) {
|
|
148
168
|
const [k, c] = processDateCondition(key, condition);
|
149
169
|
where[k] = c;
|
150
170
|
} else {
|
151
|
-
const processedCondition = processCondition(condition);
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
171
|
+
const processedCondition = processCondition(condition, key);
|
172
|
+
|
173
|
+
// Se retornar um Sequelize.where (case insensitive para MariaDB), precisamos tratar diferente
|
174
|
+
if (processedCondition && typeof processedCondition === 'object' && processedCondition.comparator) {
|
175
|
+
// É um Sequelize.where
|
176
|
+
where[_sequelize.Op.and] = where[_sequelize.Op.and] || [];
|
177
|
+
where[_sequelize.Op.and].push(processedCondition);
|
157
178
|
} else {
|
158
|
-
|
179
|
+
// Condição normal
|
180
|
+
if (where[field]) {
|
181
|
+
where[field] = {
|
182
|
+
...where[field],
|
183
|
+
...processedCondition
|
184
|
+
};
|
185
|
+
} else {
|
186
|
+
where[field] = processedCondition;
|
187
|
+
}
|
159
188
|
}
|
160
189
|
}
|
161
190
|
}
|