@strapi/database 5.12.0-beta.1 → 5.12.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
@@ -5303,7 +5303,8 @@ const createQueryBuilder = (uid, db, initialState = {})=>{
5303
5303
  decrements: [],
5304
5304
  aliasCounter: 0,
5305
5305
  filters: null,
5306
- search: null
5306
+ search: null,
5307
+ processed: false
5307
5308
  }, initialState);
5308
5309
  const getAlias = ()=>{
5309
5310
  const alias = `t${state.aliasCounter}`;
@@ -5508,13 +5509,17 @@ const createQueryBuilder = (uid, db, initialState = {})=>{
5508
5509
  ].includes(state.type) && state.joins.length > 0;
5509
5510
  },
5510
5511
  runSubQuery () {
5512
+ const originalType = state.type;
5511
5513
  this.select('id');
5512
5514
  const subQB = this.getKnexQuery();
5513
5515
  const nestedSubQuery = db.getConnection().select('id').from(subQB.as('subQuery'));
5514
5516
  const connection = db.getConnection(tableName);
5515
- return connection[state.type]().whereIn('id', nestedSubQuery);
5517
+ return connection[originalType]().whereIn('id', nestedSubQuery);
5516
5518
  },
5517
5519
  processState () {
5520
+ if (this.state.processed) {
5521
+ return;
5522
+ }
5518
5523
  state.orderBy = processOrderBy(state.orderBy, {
5519
5524
  qb: this,
5520
5525
  uid,
@@ -5547,6 +5552,7 @@ const createQueryBuilder = (uid, db, initialState = {})=>{
5547
5552
  });
5548
5553
  state.data = toRow(meta, state.data);
5549
5554
  this.processSelect();
5555
+ this.state.processed = true;
5550
5556
  },
5551
5557
  shouldUseDistinct () {
5552
5558
  return state.joins.length > 0 && _.isEmpty(state.groupBy);
@@ -5592,10 +5598,12 @@ const createQueryBuilder = (uid, db, initialState = {})=>{
5592
5598
  }
5593
5599
  const aliasedTableName = this.mustUseAlias() ? `${tableName} as ${this.alias}` : tableName;
5594
5600
  const qb = db.getConnection(aliasedTableName);
5601
+ // The state should always be processed before calling shouldUseSubQuery as it
5602
+ // relies on the presence or absence of joins to determine the need of a subquery
5603
+ this.processState();
5595
5604
  if (this.shouldUseSubQuery()) {
5596
5605
  return this.runSubQuery();
5597
5606
  }
5598
- this.processState();
5599
5607
  switch(state.type){
5600
5608
  case 'select':
5601
5609
  {
@@ -6749,7 +6757,9 @@ const createEntityManager = (db)=>{
6749
6757
  params
6750
6758
  });
6751
6759
  const { where } = params;
6752
- const deletedRows = await this.createQueryBuilder(uid).where(where).delete().execute();
6760
+ const deletedRows = await this.createQueryBuilder(uid).where(where).delete().execute({
6761
+ mapResults: false
6762
+ });
6753
6763
  const result = {
6754
6764
  count: deletedRows
6755
6765
  };