Typeorm subqueries is giving me error driver not connected

const mainQueryBuilder =  dataSource
      .createQueryBuilder()
      .select([
        'first_order_date',
        'COUNT(CASE WHEN first_order_date = first_created THEN 1 END) as NewActive',
        'COUNT(CASE WHEN first_order_date > first_created THEN 1 END) as BecameActive',
      ])
      .from((subQuery) => {
        return subQuery
          .select(
            "TO_CHAR(date_trunc('month', MIN(o.created_at)), 'YYYY-MM') AS first_order_date",
            "TO_CHAR(date_trunc('month', MIN(b.created_at)), 'YYYY-MM') AS first_created",
          )
          .from('businesses', 'b')
          .leftJoin('orders', 'o', 'o.business_id = b.id')
          .groupBy('b.id')
      }, 'date')
      .where('first_order_date IS NOT NULL')
      .groupBy('first_order_date')
      .orderBy({'first_order_date': 'ASC'})
       //mainQueryBuilder should be for Prior signup and New active`;

console.log(await mainQueryBuilder.getRawMany(), "result");

I did try this
https://github.com/typeorm/typeorm/issues/4015#issuecomment-1551955112

but after that I was experiencing the error [12:37:24.232] ERROR (15609): Driver not Connected

Even tho after commenting this query its giving me output for every other queries that are not related to this

  • 1

    Hey @toyotaSupra, thanks for refactoring the code. If you find any solution please help me.

    – 




Leave a Comment