@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.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import path$1 from "node:path";
1
2
  import path from "path";
2
3
  import fse from "fs-extra";
3
4
  import createDebug from "debug";
@@ -4890,10 +4891,8 @@ const encodePolymorphicRelation = curry(({ idColumn, typeColumn }, relation) =>
4890
4891
  const { before, after } = relation.position;
4891
4892
  const __type = relation.position.__type || relation.__type;
4892
4893
  newRelation.position = { ...relation.position };
4893
- if (before)
4894
- newRelation.position.before = encodePolymorphicId(before, __type);
4895
- if (after)
4896
- newRelation.position.after = encodePolymorphicId(after, __type);
4894
+ if (before) newRelation.position.before = encodePolymorphicId(before, __type);
4895
+ if (after) newRelation.position.after = encodePolymorphicId(after, __type);
4897
4896
  }
4898
4897
  return newRelation;
4899
4898
  });
@@ -5041,8 +5040,7 @@ const cleanOrderColumns = async ({
5041
5040
  }
5042
5041
  };
5043
5042
  const updateInverseOrderColumn = async () => {
5044
- if (!hasInverseOrderColumn(attribute) || isEmpty(inverseRelIds))
5045
- return;
5043
+ if (!hasInverseOrderColumn(attribute) || isEmpty(inverseRelIds)) return;
5046
5044
  const selectRowsToOrder = (joinTableName) => db.connection(joinTableName).select("id").rowNumber("inv_order", inverseOrderColumnName, inverseJoinColumn.name).where(inverseJoinColumn.name, "in", inverseRelIds).toSQL();
5047
5045
  switch (strapi.db.dialect.client) {
5048
5046
  case "mysql": {
@@ -5098,8 +5096,7 @@ const sortConnectArray = (connectArr, initialArr = [], strictSort = true) => {
5098
5096
  },
5099
5097
  {}
5100
5098
  );
5101
- if (!needsSorting)
5102
- return connectArr;
5099
+ if (!needsSorting) return connectArr;
5103
5100
  const computeRelation = (relation, relationsSeenInBranch) => {
5104
5101
  const adjacentRelId = relation.position?.before || relation.position?.after;
5105
5102
  const adjacentRelation = mappedRelations[adjacentRelId];
@@ -5207,8 +5204,7 @@ const relationsOrderer = (initArr, idColumn, orderColumn, strict2) => {
5207
5204
  getOrderMap() {
5208
5205
  return _$1(computedRelations).groupBy("order").reduce(
5209
5206
  (acc, relations) => {
5210
- if (relations[0]?.init)
5211
- return acc;
5207
+ if (relations[0]?.init) return acc;
5212
5208
  relations.forEach((relation, idx) => {
5213
5209
  acc[relation.id] = Math.floor(relation.order) + (idx + 1) / (relations.length + 1);
5214
5210
  });
@@ -5887,8 +5883,7 @@ const createEntityManager = (db) => {
5887
5883
  const isPartialUpdate = !has("set", cleanRelationData);
5888
5884
  let relIdsToaddOrMove;
5889
5885
  if (isPartialUpdate) {
5890
- if (isAnyToOne(attribute))
5891
- ;
5886
+ if (isAnyToOne(attribute)) ;
5892
5887
  relIdsToaddOrMove = toIds(cleanRelationData.connect);
5893
5888
  const relIdsToDelete = toIds(
5894
5889
  differenceWith(
@@ -6076,8 +6071,7 @@ const createEntityManager = (db) => {
6076
6071
  }
6077
6072
  continue;
6078
6073
  }
6079
- if (attribute.relation === "morphToOne")
6080
- ;
6074
+ if (attribute.relation === "morphToOne") ;
6081
6075
  if (attribute.relation === "morphToMany") {
6082
6076
  const { joinTable } = attribute;
6083
6077
  const { joinColumn } = joinTable;
@@ -6281,7 +6275,7 @@ const QUERIES = {
6281
6275
  SELECT :tableName:.id as id, string_agg(DISTINCT :inverseJoinColumn:::character varying, ',') as other_ids
6282
6276
  FROM :tableName:
6283
6277
  LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:
6284
- WHERE document_id IS NULL
6278
+ WHERE :tableName:.document_id IS NULL
6285
6279
  GROUP BY :tableName:.id, :joinTableName:.:joinColumn:
6286
6280
  LIMIT 1;
6287
6281
  `,
@@ -6295,7 +6289,7 @@ const QUERIES = {
6295
6289
  SELECT :tableName:.id as id, group_concat(DISTINCT :inverseJoinColumn:) as other_ids
6296
6290
  FROM :tableName:
6297
6291
  LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:
6298
- WHERE document_id IS NULL
6292
+ WHERE :tableName:.document_id IS NULL
6299
6293
  GROUP BY :tableName:.id, :joinTableName:.:joinColumn:
6300
6294
  LIMIT 1;
6301
6295
  `,
@@ -6309,7 +6303,7 @@ const QUERIES = {
6309
6303
  SELECT :tableName:.id as id, group_concat(DISTINCT :inverseJoinColumn:) as other_ids
6310
6304
  FROM :tableName:
6311
6305
  LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:
6312
- WHERE document_id IS NULL
6306
+ WHERE :tableName:.document_id IS NULL
6313
6307
  GROUP BY :joinTableName:.:joinColumn:
6314
6308
  LIMIT 1;
6315
6309
  `,
@@ -6873,8 +6867,7 @@ const getLinksWithoutMappedBy = (db) => {
6873
6867
  };
6874
6868
  const isLinkTableEmpty = async (db, linkTableName) => {
6875
6869
  const exists = await db.getSchemaConnection().hasTable(linkTableName);
6876
- if (!exists)
6877
- return true;
6870
+ if (!exists) return true;
6878
6871
  const result = await db.getConnection().from(linkTableName).count("* as count");
6879
6872
  return Number(result[0].count) === 0;
6880
6873
  };
@@ -6901,8 +6894,7 @@ const validateBidirectionalRelations = async (db) => {
6901
6894
  process.emitWarning(
6902
6895
  `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}" }`
6903
6896
  );
6904
- } else
6905
- ;
6897
+ } else ;
6906
6898
  }
6907
6899
  };
6908
6900
  const validateRelations = async (db) => {
@@ -7026,6 +7018,27 @@ class Database {
7026
7018
  const connection = tableName ? this.connection(tableName) : this.connection;
7027
7019
  return schema ? connection.withSchema(schema) : connection;
7028
7020
  }
7021
+ // Returns basic info about the database connection
7022
+ getInfo() {
7023
+ const connectionSettings = this.connection?.client?.connectionSettings || {};
7024
+ const client = this.dialect?.client || "";
7025
+ let displayName = "";
7026
+ let schema;
7027
+ if (client === "sqlite") {
7028
+ const absolutePath = connectionSettings?.filename;
7029
+ if (absolutePath) {
7030
+ displayName = path$1.relative(process.cwd(), absolutePath);
7031
+ }
7032
+ } else {
7033
+ displayName = connectionSettings?.database;
7034
+ schema = connectionSettings?.schema;
7035
+ }
7036
+ return {
7037
+ displayName,
7038
+ schema,
7039
+ client
7040
+ };
7041
+ }
7029
7042
  getSchemaConnection(trx = this.connection) {
7030
7043
  const schema = this.getSchemaName();
7031
7044
  return schema ? trx.schema.withSchema(schema) : trx.schema;