Search code examples
nestjstypeorm

Why skip() and take() not works when I use getRawMany() in nestJS with typeorm?


Here is the code I currently use.

with getRawMany() - skip and take not works!

const data = await getRepository(Enquiry)
  .createQueryBuilder('enq')
  .select([
    'enq.id AS id',
    'enq.location AS location',
    'enqStatus.name AS status'
  ])
  .leftJoin('enq.status', 'enqStatus')
  .skip(1)
  .take(3)
  .where(payload)
  .getRawMany()


Solution

  • Try with limit and offset

    const data = await getRepository(Enquiry)
      .createQueryBuilder('enq')
      .select([
        'enq.id AS id',
        'enq.location AS location',
        'enqStatus.name AS status'
      ])
      .leftJoin('enq.status', 'enqStatus')
      .where(payload)
      .offset(meta.page)
      .limit(meta.pageSize)
      .getRawMany()