@strapi/database 4.3.6 → 4.3.7
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/dialects/dialect.js
CHANGED
|
@@ -24,6 +24,10 @@ class SqliteDialect extends Dialect {
|
|
|
24
24
|
fse.ensureDirSync(dbDir);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
useReturning() {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
27
31
|
async initialize() {
|
|
28
32
|
await this.db.connection.raw('pragma foreign_keys = on');
|
|
29
33
|
}
|
|
@@ -68,6 +72,10 @@ class SqliteDialect extends Dialect {
|
|
|
68
72
|
}
|
|
69
73
|
}
|
|
70
74
|
}
|
|
75
|
+
|
|
76
|
+
canAddIncrements() {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
module.exports = SqliteDialect;
|
package/lib/entity-manager.js
CHANGED
|
@@ -776,7 +776,6 @@ const createEntityManager = (db) => {
|
|
|
776
776
|
}
|
|
777
777
|
},
|
|
778
778
|
|
|
779
|
-
// TODO: support multiple relations at once with the populate syntax
|
|
780
779
|
// TODO: add lifecycle events
|
|
781
780
|
async populate(uid, entity, populate) {
|
|
782
781
|
const entry = await this.findOne(uid, {
|
|
@@ -788,30 +787,37 @@ const createEntityManager = (db) => {
|
|
|
788
787
|
return { ...entity, ...entry };
|
|
789
788
|
},
|
|
790
789
|
|
|
791
|
-
// TODO: support multiple relations at once with the populate syntax
|
|
792
790
|
// TODO: add lifecycle events
|
|
793
|
-
async load(uid, entity,
|
|
791
|
+
async load(uid, entity, fields, params) {
|
|
794
792
|
const { attributes } = db.metadata.get(uid);
|
|
795
793
|
|
|
796
|
-
const
|
|
794
|
+
const fieldsArr = _.castArray(fields);
|
|
795
|
+
fieldsArr.forEach((field) => {
|
|
796
|
+
const attribute = attributes[field];
|
|
797
797
|
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
798
|
+
if (!attribute || attribute.type !== 'relation') {
|
|
799
|
+
throw new Error(`Invalid load. Expected ${field} to be a relational attribute`);
|
|
800
|
+
}
|
|
801
|
+
});
|
|
801
802
|
|
|
802
803
|
const entry = await this.findOne(uid, {
|
|
803
804
|
select: ['id'],
|
|
804
805
|
where: { id: entity.id },
|
|
805
|
-
populate: {
|
|
806
|
-
[field]
|
|
807
|
-
|
|
806
|
+
populate: fieldsArr.reduce((acc, field) => {
|
|
807
|
+
acc[field] = params || true;
|
|
808
|
+
return acc;
|
|
809
|
+
}, {}),
|
|
808
810
|
});
|
|
809
811
|
|
|
810
812
|
if (!entry) {
|
|
811
813
|
return null;
|
|
812
814
|
}
|
|
813
815
|
|
|
814
|
-
|
|
816
|
+
if (Array.isArray(fields)) {
|
|
817
|
+
return _.pick(fields, entry);
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
return entry[fields];
|
|
815
821
|
},
|
|
816
822
|
|
|
817
823
|
// cascading
|
|
@@ -206,6 +206,9 @@ const createMorphToMany = (attributeName, attribute, meta, metadata) => {
|
|
|
206
206
|
uid: joinTableName,
|
|
207
207
|
tableName: joinTableName,
|
|
208
208
|
attributes: {
|
|
209
|
+
id: {
|
|
210
|
+
type: 'increments',
|
|
211
|
+
},
|
|
209
212
|
[joinColumnName]: {
|
|
210
213
|
type: 'integer',
|
|
211
214
|
column: {
|
|
@@ -404,6 +407,9 @@ const createJoinTable = (metadata, { attributeName, attribute, meta }) => {
|
|
|
404
407
|
uid: joinTableName,
|
|
405
408
|
tableName: joinTableName,
|
|
406
409
|
attributes: {
|
|
410
|
+
id: {
|
|
411
|
+
type: 'increments',
|
|
412
|
+
},
|
|
407
413
|
[joinColumnName]: {
|
|
408
414
|
type: 'integer',
|
|
409
415
|
column: {
|
package/lib/schema/builder.js
CHANGED
|
@@ -290,13 +290,16 @@ const createHelpers = (db) => {
|
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
// Update existing columns / foreign keys / indexes
|
|
293
|
-
|
|
294
293
|
for (const updatedColumn of table.columns.updated) {
|
|
295
294
|
debug(`Updating column ${updatedColumn.name}`);
|
|
296
295
|
|
|
297
296
|
const { object } = updatedColumn;
|
|
298
297
|
|
|
299
|
-
|
|
298
|
+
if (object.type === 'increments') {
|
|
299
|
+
createColumn(tableBuilder, { ...object, type: 'integer' }).alter();
|
|
300
|
+
} else {
|
|
301
|
+
createColumn(tableBuilder, object).alter();
|
|
302
|
+
}
|
|
300
303
|
}
|
|
301
304
|
|
|
302
305
|
for (const updatedForeignKey of table.foreignKeys.updated) {
|
|
@@ -311,7 +314,13 @@ const createHelpers = (db) => {
|
|
|
311
314
|
|
|
312
315
|
for (const addedColumn of table.columns.added) {
|
|
313
316
|
debug(`Creating column ${addedColumn.name}`);
|
|
314
|
-
|
|
317
|
+
|
|
318
|
+
if (addedColumn.type === 'increments' && !db.dialect.canAddIncrements()) {
|
|
319
|
+
tableBuilder.integer(addedColumn.name).unsigned().notNullable();
|
|
320
|
+
tableBuilder.primary(addedColumn.name);
|
|
321
|
+
} else {
|
|
322
|
+
createColumn(tableBuilder, addedColumn);
|
|
323
|
+
}
|
|
315
324
|
}
|
|
316
325
|
|
|
317
326
|
for (const addedForeignKey of table.foreignKeys.added) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/database",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.7",
|
|
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": "73f523b98322cea8992c72977b94a73a624d2e79"
|
|
46
46
|
}
|