@strapi/database 5.4.1 → 5.5.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/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -46,6 +46,11 @@ declare class Database {
|
|
|
46
46
|
getSchemaName(): string | undefined;
|
|
47
47
|
getConnection(): Knex;
|
|
48
48
|
getConnection(tableName?: string): Knex.QueryBuilder;
|
|
49
|
+
getInfo(): {
|
|
50
|
+
displayName: string;
|
|
51
|
+
schema: any;
|
|
52
|
+
client: string;
|
|
53
|
+
};
|
|
49
54
|
getSchemaConnection(trx?: Knex<any, any[]>): Knex.SchemaBuilder;
|
|
50
55
|
queryBuilder(uid: string): import("./query/query-builder").QueryBuilder;
|
|
51
56
|
destroy(): Promise<void>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAGjC,OAAO,EAAE,OAAO,EAAc,MAAM,YAAY,CAAC;AACjD,OAAO,EAAwB,cAAc,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAkB,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAuB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAA4B,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAA4B,iBAAiB,EAAE,MAAM,cAAc,CA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QAAE,MAAM,EAAE,KAAK,EAAE,CAAA;KAAE;IA2B1C,KAAK,CAAC,GAAG,EAAE,MAAM;IAQjB,aAAa;IAIb,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IACzC,WAAW,CAAC,SAAS,SAAS,QAAQ,EAAE,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IA4CrF,aAAa,IAAI,MAAM,GAAG,SAAS;IAInC,aAAa,IAAI,IAAI;IACrB,aAAa,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,YAAY;IAQpD,OAAO;;;;;IA2BP,mBAAmB,CAAC,GAAG,mBAAkB;IAKzC,YAAY,CAAC,GAAG,EAAE,MAAM;IAIlB,OAAO;CAId;AAED,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC5B,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const path$1 = require("node:path");
|
|
3
4
|
const path = require("path");
|
|
4
5
|
const fse = require("fs-extra");
|
|
5
6
|
const createDebug = require("debug");
|
|
@@ -19,8 +20,7 @@ const assert = require("assert");
|
|
|
19
20
|
const knex = require("knex");
|
|
20
21
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
21
22
|
function _interopNamespace(e) {
|
|
22
|
-
if (e && e.__esModule)
|
|
23
|
-
return e;
|
|
23
|
+
if (e && e.__esModule) return e;
|
|
24
24
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
25
25
|
if (e) {
|
|
26
26
|
for (const k in e) {
|
|
@@ -36,6 +36,7 @@ function _interopNamespace(e) {
|
|
|
36
36
|
n.default = e;
|
|
37
37
|
return Object.freeze(n);
|
|
38
38
|
}
|
|
39
|
+
const path__default$1 = /* @__PURE__ */ _interopDefault(path$1);
|
|
39
40
|
const path__default = /* @__PURE__ */ _interopDefault(path);
|
|
40
41
|
const fse__default = /* @__PURE__ */ _interopDefault(fse);
|
|
41
42
|
const createDebug__default = /* @__PURE__ */ _interopDefault(createDebug);
|
|
@@ -4922,10 +4923,8 @@ const encodePolymorphicRelation = _.curry(({ idColumn, typeColumn }, relation) =
|
|
|
4922
4923
|
const { before, after } = relation.position;
|
|
4923
4924
|
const __type = relation.position.__type || relation.__type;
|
|
4924
4925
|
newRelation.position = { ...relation.position };
|
|
4925
|
-
if (before)
|
|
4926
|
-
|
|
4927
|
-
if (after)
|
|
4928
|
-
newRelation.position.after = encodePolymorphicId(after, __type);
|
|
4926
|
+
if (before) newRelation.position.before = encodePolymorphicId(before, __type);
|
|
4927
|
+
if (after) newRelation.position.after = encodePolymorphicId(after, __type);
|
|
4929
4928
|
}
|
|
4930
4929
|
return newRelation;
|
|
4931
4930
|
});
|
|
@@ -5073,8 +5072,7 @@ const cleanOrderColumns = async ({
|
|
|
5073
5072
|
}
|
|
5074
5073
|
};
|
|
5075
5074
|
const updateInverseOrderColumn = async () => {
|
|
5076
|
-
if (!hasInverseOrderColumn(attribute) || _.isEmpty(inverseRelIds))
|
|
5077
|
-
return;
|
|
5075
|
+
if (!hasInverseOrderColumn(attribute) || _.isEmpty(inverseRelIds)) return;
|
|
5078
5076
|
const selectRowsToOrder = (joinTableName) => db.connection(joinTableName).select("id").rowNumber("inv_order", inverseOrderColumnName, inverseJoinColumn.name).where(inverseJoinColumn.name, "in", inverseRelIds).toSQL();
|
|
5079
5077
|
switch (strapi.db.dialect.client) {
|
|
5080
5078
|
case "mysql": {
|
|
@@ -5130,8 +5128,7 @@ const sortConnectArray = (connectArr, initialArr = [], strictSort = true) => {
|
|
|
5130
5128
|
},
|
|
5131
5129
|
{}
|
|
5132
5130
|
);
|
|
5133
|
-
if (!needsSorting)
|
|
5134
|
-
return connectArr;
|
|
5131
|
+
if (!needsSorting) return connectArr;
|
|
5135
5132
|
const computeRelation = (relation, relationsSeenInBranch) => {
|
|
5136
5133
|
const adjacentRelId = relation.position?.before || relation.position?.after;
|
|
5137
5134
|
const adjacentRelation = mappedRelations[adjacentRelId];
|
|
@@ -5239,8 +5236,7 @@ const relationsOrderer = (initArr, idColumn, orderColumn, strict) => {
|
|
|
5239
5236
|
getOrderMap() {
|
|
5240
5237
|
return ___default$1.default(computedRelations).groupBy("order").reduce(
|
|
5241
5238
|
(acc, relations) => {
|
|
5242
|
-
if (relations[0]?.init)
|
|
5243
|
-
return acc;
|
|
5239
|
+
if (relations[0]?.init) return acc;
|
|
5244
5240
|
relations.forEach((relation, idx) => {
|
|
5245
5241
|
acc[relation.id] = Math.floor(relation.order) + (idx + 1) / (relations.length + 1);
|
|
5246
5242
|
});
|
|
@@ -5919,8 +5915,7 @@ const createEntityManager = (db) => {
|
|
|
5919
5915
|
const isPartialUpdate = !_.has("set", cleanRelationData);
|
|
5920
5916
|
let relIdsToaddOrMove;
|
|
5921
5917
|
if (isPartialUpdate) {
|
|
5922
|
-
if (isAnyToOne(attribute))
|
|
5923
|
-
;
|
|
5918
|
+
if (isAnyToOne(attribute)) ;
|
|
5924
5919
|
relIdsToaddOrMove = toIds(cleanRelationData.connect);
|
|
5925
5920
|
const relIdsToDelete = toIds(
|
|
5926
5921
|
_.differenceWith(
|
|
@@ -6108,8 +6103,7 @@ const createEntityManager = (db) => {
|
|
|
6108
6103
|
}
|
|
6109
6104
|
continue;
|
|
6110
6105
|
}
|
|
6111
|
-
if (attribute.relation === "morphToOne")
|
|
6112
|
-
;
|
|
6106
|
+
if (attribute.relation === "morphToOne") ;
|
|
6113
6107
|
if (attribute.relation === "morphToMany") {
|
|
6114
6108
|
const { joinTable } = attribute;
|
|
6115
6109
|
const { joinColumn } = joinTable;
|
|
@@ -6313,7 +6307,7 @@ const QUERIES = {
|
|
|
6313
6307
|
SELECT :tableName:.id as id, string_agg(DISTINCT :inverseJoinColumn:::character varying, ',') as other_ids
|
|
6314
6308
|
FROM :tableName:
|
|
6315
6309
|
LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:
|
|
6316
|
-
WHERE document_id IS NULL
|
|
6310
|
+
WHERE :tableName:.document_id IS NULL
|
|
6317
6311
|
GROUP BY :tableName:.id, :joinTableName:.:joinColumn:
|
|
6318
6312
|
LIMIT 1;
|
|
6319
6313
|
`,
|
|
@@ -6327,7 +6321,7 @@ const QUERIES = {
|
|
|
6327
6321
|
SELECT :tableName:.id as id, group_concat(DISTINCT :inverseJoinColumn:) as other_ids
|
|
6328
6322
|
FROM :tableName:
|
|
6329
6323
|
LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:
|
|
6330
|
-
WHERE document_id IS NULL
|
|
6324
|
+
WHERE :tableName:.document_id IS NULL
|
|
6331
6325
|
GROUP BY :tableName:.id, :joinTableName:.:joinColumn:
|
|
6332
6326
|
LIMIT 1;
|
|
6333
6327
|
`,
|
|
@@ -6341,7 +6335,7 @@ const QUERIES = {
|
|
|
6341
6335
|
SELECT :tableName:.id as id, group_concat(DISTINCT :inverseJoinColumn:) as other_ids
|
|
6342
6336
|
FROM :tableName:
|
|
6343
6337
|
LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:
|
|
6344
|
-
WHERE document_id IS NULL
|
|
6338
|
+
WHERE :tableName:.document_id IS NULL
|
|
6345
6339
|
GROUP BY :joinTableName:.:joinColumn:
|
|
6346
6340
|
LIMIT 1;
|
|
6347
6341
|
`,
|
|
@@ -6905,8 +6899,7 @@ const getLinksWithoutMappedBy = (db) => {
|
|
|
6905
6899
|
};
|
|
6906
6900
|
const isLinkTableEmpty = async (db, linkTableName) => {
|
|
6907
6901
|
const exists = await db.getSchemaConnection().hasTable(linkTableName);
|
|
6908
|
-
if (!exists)
|
|
6909
|
-
return true;
|
|
6902
|
+
if (!exists) return true;
|
|
6910
6903
|
const result = await db.getConnection().from(linkTableName).count("* as count");
|
|
6911
6904
|
return Number(result[0].count) === 0;
|
|
6912
6905
|
};
|
|
@@ -6933,8 +6926,7 @@ const validateBidirectionalRelations = async (db) => {
|
|
|
6933
6926
|
process.emitWarning(
|
|
6934
6927
|
`Error on attribute "${relation.inversedBy}" in model "${invModelMetadata.singularName}" (${invModelMetadata.uid}). Please modify your ${invModelMetadata.singularName} schema by renaming the key "inversedBy" to "mappedBy". Ex: { "inversedBy": "${invRelation.inversedBy}" } -> { "mappedBy": "${invRelation.inversedBy}" }`
|
|
6935
6928
|
);
|
|
6936
|
-
} else
|
|
6937
|
-
;
|
|
6929
|
+
} else ;
|
|
6938
6930
|
}
|
|
6939
6931
|
};
|
|
6940
6932
|
const validateRelations = async (db) => {
|
|
@@ -7058,6 +7050,27 @@ class Database {
|
|
|
7058
7050
|
const connection = tableName ? this.connection(tableName) : this.connection;
|
|
7059
7051
|
return schema ? connection.withSchema(schema) : connection;
|
|
7060
7052
|
}
|
|
7053
|
+
// Returns basic info about the database connection
|
|
7054
|
+
getInfo() {
|
|
7055
|
+
const connectionSettings = this.connection?.client?.connectionSettings || {};
|
|
7056
|
+
const client = this.dialect?.client || "";
|
|
7057
|
+
let displayName = "";
|
|
7058
|
+
let schema;
|
|
7059
|
+
if (client === "sqlite") {
|
|
7060
|
+
const absolutePath = connectionSettings?.filename;
|
|
7061
|
+
if (absolutePath) {
|
|
7062
|
+
displayName = path__default$1.default.relative(process.cwd(), absolutePath);
|
|
7063
|
+
}
|
|
7064
|
+
} else {
|
|
7065
|
+
displayName = connectionSettings?.database;
|
|
7066
|
+
schema = connectionSettings?.schema;
|
|
7067
|
+
}
|
|
7068
|
+
return {
|
|
7069
|
+
displayName,
|
|
7070
|
+
schema,
|
|
7071
|
+
client
|
|
7072
|
+
};
|
|
7073
|
+
}
|
|
7061
7074
|
getSchemaConnection(trx = this.connection) {
|
|
7062
7075
|
const schema = this.getSchemaName();
|
|
7063
7076
|
return schema ? trx.schema.withSchema(schema) : trx.schema;
|