@strapi/database 4.2.3 → 4.3.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.
- package/lib/entity-manager.js +1 -1
- package/lib/index.d.ts +25 -4
- package/lib/index.js +4 -0
- package/lib/metadata/index.js +1 -0
- package/lib/migrations/index.js +1 -1
- package/lib/query/helpers/where.js +13 -1
- package/lib/query/query-builder.js +37 -1
- package/package.json +2 -2
package/lib/entity-manager.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -2,16 +2,37 @@ import { LifecycleProvider } from './lifecycles';
|
|
|
2
2
|
import { MigrationProvider } from './migrations';
|
|
3
3
|
import { SchemaProvideer } from './schema';
|
|
4
4
|
|
|
5
|
-
type
|
|
5
|
+
type LogicalOperators<T> = {
|
|
6
6
|
$and?: WhereParams<T>[];
|
|
7
7
|
$or?: WhereParams<T>[];
|
|
8
8
|
$not?: WhereParams<T>;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
type
|
|
12
|
-
[K
|
|
11
|
+
type AttributeOperators<T, K extends keyof T> = {
|
|
12
|
+
$eq?: T[K] | Array<T[K]>;
|
|
13
|
+
$ne?: T[K] | Array<T[K]>;
|
|
14
|
+
$in?: T[K][];
|
|
15
|
+
$notIn?: T[K][];
|
|
16
|
+
$lt?: T[K];
|
|
17
|
+
$lte?: T[K];
|
|
18
|
+
$gt?: T[K];
|
|
19
|
+
$gte?: T[K];
|
|
20
|
+
$between?: [T[K], T[K]];
|
|
21
|
+
$contains?: T[K];
|
|
22
|
+
$notContains?: T[K];
|
|
23
|
+
$containsi?: T[K];
|
|
24
|
+
$notContainsi?: T[K];
|
|
25
|
+
$startsWith?: T[K];
|
|
26
|
+
$endsWith?: T[K];
|
|
27
|
+
$null?: boolean;
|
|
28
|
+
$notNull?: boolean;
|
|
29
|
+
$not?: WhereParams<T> | AttributeOperators<T, K>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type WhereParams<T> = {
|
|
33
|
+
[K in keyof T]?: T[K] | T[K][] | AttributeOperators<T, K>;
|
|
13
34
|
} &
|
|
14
|
-
|
|
35
|
+
LogicalOperators<T>;
|
|
15
36
|
|
|
16
37
|
type Sortables<T> = {
|
|
17
38
|
// check sortable
|
package/lib/index.js
CHANGED
package/lib/metadata/index.js
CHANGED
package/lib/migrations/index.js
CHANGED
|
@@ -34,7 +34,7 @@ const migrationResolver = ({ name, path, context }) => {
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
const createUmzugProvider = db => {
|
|
37
|
-
const migrationDir = path.join(strapi.dirs.root, 'database/migrations');
|
|
37
|
+
const migrationDir = path.join(strapi.dirs.app.root, 'database/migrations');
|
|
38
38
|
|
|
39
39
|
fse.ensureDirSync(migrationDir);
|
|
40
40
|
|
|
@@ -13,6 +13,7 @@ const OPERATORS = [
|
|
|
13
13
|
'$in',
|
|
14
14
|
'$notIn',
|
|
15
15
|
'$eq',
|
|
16
|
+
'$eqi',
|
|
16
17
|
'$ne',
|
|
17
18
|
'$gt',
|
|
18
19
|
'$gte',
|
|
@@ -133,7 +134,9 @@ const processWhere = (where, ctx) => {
|
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
if (isOperator(key)) {
|
|
136
|
-
throw new Error(
|
|
137
|
+
throw new Error(
|
|
138
|
+
`Only $and, $or and $not can only be used as root level operators. Found ${key}.`
|
|
139
|
+
);
|
|
137
140
|
}
|
|
138
141
|
|
|
139
142
|
const attribute = meta.attributes[key];
|
|
@@ -221,6 +224,15 @@ const applyOperator = (qb, column, operator, value) => {
|
|
|
221
224
|
qb.where(column, value);
|
|
222
225
|
break;
|
|
223
226
|
}
|
|
227
|
+
|
|
228
|
+
case '$eqi': {
|
|
229
|
+
if (value === null) {
|
|
230
|
+
qb.whereNull(column);
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
qb.whereRaw(`${fieldLowerFn(qb)} LIKE LOWER(?)`, [column, `${value}`]);
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
224
236
|
case '$ne': {
|
|
225
237
|
if (value === null) {
|
|
226
238
|
qb.whereNotNull(column);
|
|
@@ -12,6 +12,7 @@ const createQueryBuilder = (uid, db) => {
|
|
|
12
12
|
type: 'select',
|
|
13
13
|
select: [],
|
|
14
14
|
count: null,
|
|
15
|
+
max: null,
|
|
15
16
|
first: false,
|
|
16
17
|
data: null,
|
|
17
18
|
where: [],
|
|
@@ -19,6 +20,8 @@ const createQueryBuilder = (uid, db) => {
|
|
|
19
20
|
populate: null,
|
|
20
21
|
limit: null,
|
|
21
22
|
offset: null,
|
|
23
|
+
transaction: null,
|
|
24
|
+
forUpdate: false,
|
|
22
25
|
orderBy: [],
|
|
23
26
|
groupBy: [],
|
|
24
27
|
};
|
|
@@ -75,6 +78,13 @@ const createQueryBuilder = (uid, db) => {
|
|
|
75
78
|
return this;
|
|
76
79
|
},
|
|
77
80
|
|
|
81
|
+
max(column) {
|
|
82
|
+
state.type = 'max';
|
|
83
|
+
state.max = column;
|
|
84
|
+
|
|
85
|
+
return this;
|
|
86
|
+
},
|
|
87
|
+
|
|
78
88
|
where(where = {}) {
|
|
79
89
|
if (!_.isPlainObject(where)) {
|
|
80
90
|
throw new Error('Where must be an object');
|
|
@@ -115,6 +125,16 @@ const createQueryBuilder = (uid, db) => {
|
|
|
115
125
|
return this;
|
|
116
126
|
},
|
|
117
127
|
|
|
128
|
+
transacting(transaction) {
|
|
129
|
+
state.transaction = transaction;
|
|
130
|
+
return this;
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
forUpdate() {
|
|
134
|
+
state.forUpdate = true;
|
|
135
|
+
return this;
|
|
136
|
+
},
|
|
137
|
+
|
|
118
138
|
init(params = {}) {
|
|
119
139
|
const { _q, filters, where, select, limit, offset, orderBy, groupBy, populate } = params;
|
|
120
140
|
|
|
@@ -281,7 +301,15 @@ const createQueryBuilder = (uid, db) => {
|
|
|
281
301
|
break;
|
|
282
302
|
}
|
|
283
303
|
case 'count': {
|
|
284
|
-
|
|
304
|
+
const dbColumnName =
|
|
305
|
+
state.count === '*' ? '*' : this.aliasColumn(helpers.toColumnName(meta, state.count));
|
|
306
|
+
|
|
307
|
+
qb.count({ count: dbColumnName });
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
case 'max': {
|
|
311
|
+
const dbColumnName = this.aliasColumn(helpers.toColumnName(meta, state.max));
|
|
312
|
+
qb.max({ max: dbColumnName });
|
|
285
313
|
break;
|
|
286
314
|
}
|
|
287
315
|
case 'insert': {
|
|
@@ -308,6 +336,14 @@ const createQueryBuilder = (uid, db) => {
|
|
|
308
336
|
}
|
|
309
337
|
}
|
|
310
338
|
|
|
339
|
+
if (state.transaction) {
|
|
340
|
+
qb.transacting(state.transaction);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (state.forUpdate) {
|
|
344
|
+
qb.forUpdate();
|
|
345
|
+
}
|
|
346
|
+
|
|
311
347
|
if (state.limit) {
|
|
312
348
|
qb.limit(state.limit);
|
|
313
349
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/database",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "Strapi's database layer",
|
|
5
5
|
"homepage": "https://strapi.io",
|
|
6
6
|
"bugs": {
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"node": ">=14.19.1 <=16.x.x",
|
|
43
43
|
"npm": ">=6.0.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "74a2b908df75bc8001d72f9dc8571c4b7a2da337"
|
|
46
46
|
}
|