How get counts of rows with limit and offset for use it in pagination?

Hi every one.
I am using this query for promotions list, and i want add the pagination to it,i used forPage(page,limit) method and it worked correctly for limit and offset,but how i can get total number of rows for use total result in pagination?

 var promotions = await Database    
 .select('Promotion.*','Country.title as country','Province.title as province','Status.code as statusCode','Status.title as statusTitle','Currency.symbol as currency')
 .from('Promotion')
 .join('Status', 'Promotion.statusId', 'Status.id')
 .join('Currency', 'Promotion.valueCurrencyId', 'Currency.id')
 .join('Country', 'Promotion.countryId', 'Country.id')
 .leftJoin('Province', 'Promotion.provinceId', 'Province.id')
 .orderBy('ordering')
 .where(function () {
      if(request.qs && request.qs.statusId && request.qs.statusId!=0)
         this.where('statusId', request.qs.statusId) 
      else 
         this.whereNotIn('statusId', [3,4])  
      if(request.body.promotionId)
         this.where('Promotion.id', request.body.promotionId)
      else if(params.promotionId)
         this.where('Promotion.id', params.promotionId)
 });

Resolved
I use paginate method :heart_eyes:

1 Like