@strapi/database 4.2.0 → 4.3.0-beta.1
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/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
|
|
|
@@ -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-beta.1",
|
|
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": "9d6555398960c39159d66bb4eea3bcb0362e37e3"
|
|
46
46
|
}
|