@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.js CHANGED
@@ -5324,7 +5324,8 @@ const createQueryBuilder = (uid, db, initialState = {})=>{
5324
5324
  decrements: [],
5325
5325
  aliasCounter: 0,
5326
5326
  filters: null,
5327
- search: null
5327
+ search: null,
5328
+ processed: false
5328
5329
  }, initialState);
5329
5330
  const getAlias = ()=>{
5330
5331
  const alias = `t${state.aliasCounter}`;
@@ -5529,13 +5530,17 @@ const createQueryBuilder = (uid, db, initialState = {})=>{
5529
5530
  ].includes(state.type) && state.joins.length > 0;
5530
5531
  },
5531
5532
  runSubQuery () {
5533
+ const originalType = state.type;
5532
5534
  this.select('id');
5533
5535
  const subQB = this.getKnexQuery();
5534
5536
  const nestedSubQuery = db.getConnection().select('id').from(subQB.as('subQuery'));
5535
5537
  const connection = db.getConnection(tableName);
5536
- return connection[state.type]().whereIn('id', nestedSubQuery);
5538
+ return connection[originalType]().whereIn('id', nestedSubQuery);
5537
5539
  },
5538
5540
  processState () {
5541
+ if (this.state.processed) {
5542
+ return;
5543
+ }
5539
5544
  state.orderBy = processOrderBy(state.orderBy, {
5540
5545
  qb: this,
5541
5546
  uid,
@@ -5568,6 +5573,7 @@ const createQueryBuilder = (uid, db, initialState = {})=>{
5568
5573
  });
5569
5574
  state.data = toRow(meta, state.data);
5570
5575
  this.processSelect();
5576
+ this.state.processed = true;
5571
5577
  },
5572
5578
  shouldUseDistinct () {
5573
5579
  return state.joins.length > 0 && _.isEmpty(state.groupBy);
@@ -5613,10 +5619,12 @@ const createQueryBuilder = (uid, db, initialState = {})=>{
5613
5619
  }
5614
5620
  const aliasedTableName = this.mustUseAlias() ? `${tableName} as ${this.alias}` : tableName;
5615
5621
  const qb = db.getConnection(aliasedTableName);
5622
+ // The state should always be processed before calling shouldUseSubQuery as it
5623
+ // relies on the presence or absence of joins to determine the need of a subquery
5624
+ this.processState();
5616
5625
  if (this.shouldUseSubQuery()) {
5617
5626
  return this.runSubQuery();
5618
5627
  }
5619
- this.processState();
5620
5628
  switch(state.type){
5621
5629
  case 'select':
5622
5630
  {
@@ -6770,7 +6778,9 @@ const createEntityManager = (db)=>{
6770
6778
  params
6771
6779
  });
6772
6780
  const { where } = params;
6773
- const deletedRows = await this.createQueryBuilder(uid).where(where).delete().execute();
6781
+ const deletedRows = await this.createQueryBuilder(uid).where(where).delete().execute({
6782
+ mapResults: false
6783
+ });
6774
6784
  const result = {
6775
6785
  count: deletedRows
6776
6786
  };