This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
Paginate function not working with Postgres #8
Open
Description
We are using a node backend application with Postgres as database.
The paginate is failing method is failing in @leapfrogtechnology/db-model@1.0.0-beta.2
The model
import BaseModel from '../baseModel';
import Table from '../common/enums/table.enum';
/**
* User Model
*/
class User extends BaseModel {
public static table: string = Table.USERS;
}
export default User;
Dao layer method call
export function fetchPaginatedUser(): Promise<any> {
const params = {
maxRows: 10,
currentPage: 1,
totalCountQuery: 'SELECT count(*) as count from users'
}
return User.paginate('SELECT * from users', params);
}
Expectation:
To get 10 rows of records.
Error message
knex:client acquired connection from pool: __knexUid2 +2s
knex:query SELECT count(*) as count from users undefined +2s
knex:bindings [] undefined +2s
knex:client releasing connection to pool: __knexUid2 +2ms
[ 2020-07-02T11:55:54.273Z ] - [ error ] Error: TypeError: Cannot read property 'count' of undefined
The error seems to have originated from
totalCount = totalRecords[0].count;
line in paginator.ts
the output of totalRecords is in the following format for postgres:
row : {
count: '99'
}
@kabirbaidhya @mesaugat @cham11ng Any suggestion on how to get it working?
Activity