@strapi/database 5.0.0-beta.8 → 5.0.0-beta.9
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/dist/index.js +47 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -9
- package/dist/index.mjs.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-03-locale.d.ts +3 -0
- package/dist/migrations/internal-migrations/5.0.0-03-locale.d.ts.map +1 -0
- package/dist/migrations/internal-migrations/index.d.ts.map +1 -1
- package/dist/query/helpers/populate/apply.d.ts.map +1 -1
- package/dist/query/helpers/where.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -3212,6 +3212,7 @@ const processOrderBy = (orderBy, ctx) => {
|
|
|
3212
3212
|
}
|
|
3213
3213
|
throw new Error("Invalid orderBy syntax");
|
|
3214
3214
|
};
|
|
3215
|
+
const joinColPrefix = "__strapi";
|
|
3215
3216
|
const XtoOne = async (input, ctx) => {
|
|
3216
3217
|
const { attribute, attributeName, results, populateValue, targetMeta, isCount } = input;
|
|
3217
3218
|
const { db, qb } = ctx;
|
|
@@ -3240,6 +3241,8 @@ const XtoOne = async (input, ctx) => {
|
|
|
3240
3241
|
const { name: joinColumnName, referencedColumn: referencedColumnName } = joinTable.joinColumn;
|
|
3241
3242
|
const alias = qb2.getAlias();
|
|
3242
3243
|
const joinColAlias = `${alias}.${joinColumnName}`;
|
|
3244
|
+
const joinColRenameAs = `${joinColPrefix}${joinColumnName}`;
|
|
3245
|
+
const joinColSelect = `${joinColAlias} as ${joinColRenameAs}`;
|
|
3243
3246
|
const referencedValues = ___default.default.uniq(
|
|
3244
3247
|
results.map((r) => r[referencedColumnName]).filter((value) => !___default.default.isNil(value))
|
|
3245
3248
|
);
|
|
@@ -3284,8 +3287,8 @@ const XtoOne = async (input, ctx) => {
|
|
|
3284
3287
|
rootTable: qb2.alias,
|
|
3285
3288
|
on: joinTable.on,
|
|
3286
3289
|
orderBy: joinTable.orderBy
|
|
3287
|
-
}).addSelect(
|
|
3288
|
-
const map = ___default.default.groupBy(
|
|
3290
|
+
}).addSelect(joinColSelect).where({ [joinColAlias]: referencedValues }).execute({ mapResults: false });
|
|
3291
|
+
const map = ___default.default.groupBy(joinColRenameAs)(rows);
|
|
3289
3292
|
results.forEach((result) => {
|
|
3290
3293
|
result[attributeName] = fromTargetRow(___default.default.first(map[result[referencedColumnName]]));
|
|
3291
3294
|
});
|
|
@@ -3319,6 +3322,8 @@ const oneToMany = async (input, ctx) => {
|
|
|
3319
3322
|
const { name: joinColumnName, referencedColumn: referencedColumnName } = joinTable.joinColumn;
|
|
3320
3323
|
const alias = qb2.getAlias();
|
|
3321
3324
|
const joinColAlias = `${alias}.${joinColumnName}`;
|
|
3325
|
+
const joinColRenameAs = `${joinColPrefix}${joinColumnName}`;
|
|
3326
|
+
const joinColSelect = `${joinColAlias} as ${joinColRenameAs}`;
|
|
3322
3327
|
const referencedValues = ___default.default.uniq(
|
|
3323
3328
|
results.map((r) => r[referencedColumnName]).filter((value) => !___default.default.isNil(value))
|
|
3324
3329
|
);
|
|
@@ -3336,10 +3341,10 @@ const oneToMany = async (input, ctx) => {
|
|
|
3336
3341
|
rootColumn: joinTable.inverseJoinColumn.referencedColumn,
|
|
3337
3342
|
rootTable: qb2.alias,
|
|
3338
3343
|
on: joinTable.on
|
|
3339
|
-
}).select([
|
|
3344
|
+
}).select([joinColSelect, qb2.raw("count(*) AS count")]).where({ [joinColAlias]: referencedValues }).groupBy(joinColAlias).execute({ mapResults: false });
|
|
3340
3345
|
const map2 = rows2.reduce(
|
|
3341
3346
|
(map3, row) => {
|
|
3342
|
-
map3[row[
|
|
3347
|
+
map3[row[joinColRenameAs]] = { count: Number(row.count) };
|
|
3343
3348
|
return map3;
|
|
3344
3349
|
},
|
|
3345
3350
|
{}
|
|
@@ -3363,8 +3368,8 @@ const oneToMany = async (input, ctx) => {
|
|
|
3363
3368
|
rootTable: qb2.alias,
|
|
3364
3369
|
on: joinTable.on,
|
|
3365
3370
|
orderBy: ___default.default.mapValues((v) => populateValue.ordering || v, joinTable.orderBy)
|
|
3366
|
-
}).addSelect(
|
|
3367
|
-
const map = ___default.default.groupBy(
|
|
3371
|
+
}).addSelect(joinColSelect).where({ [joinColAlias]: referencedValues }).execute({ mapResults: false });
|
|
3372
|
+
const map = ___default.default.groupBy(joinColRenameAs)(rows);
|
|
3368
3373
|
results.forEach((r) => {
|
|
3369
3374
|
r[attributeName] = fromTargetRow(map[r[referencedColumnName]] || []);
|
|
3370
3375
|
});
|
|
@@ -3379,6 +3384,8 @@ const manyToMany = async (input, ctx) => {
|
|
|
3379
3384
|
const { name: joinColumnName, referencedColumn: referencedColumnName } = joinTable.joinColumn;
|
|
3380
3385
|
const alias = populateQb.getAlias();
|
|
3381
3386
|
const joinColAlias = `${alias}.${joinColumnName}`;
|
|
3387
|
+
const joinColRenameAs = `${joinColPrefix}${joinColumnName}`;
|
|
3388
|
+
const joinColSelect = `${joinColAlias} as ${joinColRenameAs}`;
|
|
3382
3389
|
const referencedValues = ___default.default.uniq(
|
|
3383
3390
|
results.map((r) => r[referencedColumnName]).filter((value) => !___default.default.isNil(value))
|
|
3384
3391
|
);
|
|
@@ -3423,8 +3430,8 @@ const manyToMany = async (input, ctx) => {
|
|
|
3423
3430
|
rootTable: populateQb.alias,
|
|
3424
3431
|
on: joinTable.on,
|
|
3425
3432
|
orderBy: ___default.default.mapValues((v) => populateValue.ordering || v, joinTable.orderBy)
|
|
3426
|
-
}).addSelect(
|
|
3427
|
-
const map = ___default.default.groupBy(
|
|
3433
|
+
}).addSelect(joinColSelect).where({ [joinColAlias]: referencedValues }).execute({ mapResults: false });
|
|
3434
|
+
const map = ___default.default.groupBy(joinColRenameAs)(rows);
|
|
3428
3435
|
results.forEach((result) => {
|
|
3429
3436
|
result[attributeName] = fromTargetRow(map[result[referencedColumnName]] || []);
|
|
3430
3437
|
});
|
|
@@ -3795,6 +3802,9 @@ const processRelationWhere = (where, ctx) => {
|
|
|
3795
3802
|
}
|
|
3796
3803
|
if (operatorKeys.length === 1) {
|
|
3797
3804
|
const operator = operatorKeys[0];
|
|
3805
|
+
if (utils.isOperatorOfType("group", operator)) {
|
|
3806
|
+
return processWhere(where, ctx);
|
|
3807
|
+
}
|
|
3798
3808
|
return { [idAlias]: { [operator]: processNested(where[operator], ctx) } };
|
|
3799
3809
|
}
|
|
3800
3810
|
return processWhere(where, ctx);
|
|
@@ -6215,9 +6225,37 @@ const findDiffs = (shortMap) => {
|
|
|
6215
6225
|
});
|
|
6216
6226
|
return diffs;
|
|
6217
6227
|
};
|
|
6228
|
+
const createLocaleColumn = async (db, tableName) => {
|
|
6229
|
+
await db.schema.alterTable(tableName, (table) => {
|
|
6230
|
+
table.string("locale");
|
|
6231
|
+
});
|
|
6232
|
+
};
|
|
6233
|
+
const createdLocale = {
|
|
6234
|
+
name: "5.0.0-03-created-locale",
|
|
6235
|
+
async up(knex2, db) {
|
|
6236
|
+
for (const meta of db.metadata.values()) {
|
|
6237
|
+
const hasTable = await knex2.schema.hasTable(meta.tableName);
|
|
6238
|
+
if (!hasTable) {
|
|
6239
|
+
continue;
|
|
6240
|
+
}
|
|
6241
|
+
const uid = meta.uid;
|
|
6242
|
+
const model = strapi.getModel(uid);
|
|
6243
|
+
if (!model) {
|
|
6244
|
+
continue;
|
|
6245
|
+
}
|
|
6246
|
+
if (_.isNil(meta.attributes.locale)) {
|
|
6247
|
+
await createLocaleColumn(knex2, meta.tableName);
|
|
6248
|
+
}
|
|
6249
|
+
}
|
|
6250
|
+
},
|
|
6251
|
+
async down() {
|
|
6252
|
+
throw new Error("not implemented");
|
|
6253
|
+
}
|
|
6254
|
+
};
|
|
6218
6255
|
const internalMigrations = [
|
|
6219
6256
|
renameIdentifiersLongerThanMaxLength,
|
|
6220
|
-
createdDocumentId
|
|
6257
|
+
createdDocumentId,
|
|
6258
|
+
createdLocale
|
|
6221
6259
|
];
|
|
6222
6260
|
const createInternalMigrationProvider = (db) => {
|
|
6223
6261
|
const context = { db };
|