🐛Fixed pagination for PostgreSQL connector
This commit is contained in:
committed by
Anton Shepilov
parent
845781642f
commit
585da88b0d
+1
-1
@@ -103,7 +103,7 @@ export class PostgresQueryBuilder {
|
||||
limit = Number.parseInt(options.pagination.limitStr);
|
||||
}
|
||||
if (options.pagination.page_token) {
|
||||
offset = (Number.parseInt(options.pagination.page_token) - 1) * limit;
|
||||
offset = Number.parseInt(options.pagination.page_token) * limit;
|
||||
}
|
||||
}
|
||||
return [query(whereClause, orderByClause, limit, offset), values];
|
||||
|
||||
+9
-4
@@ -230,10 +230,7 @@ export class PostgresConnector extends AbstractConnector<PostgresConnectionOptio
|
||||
entities.push(entity);
|
||||
});
|
||||
|
||||
const nextPageToken = options?.pagination?.page_token || "0";
|
||||
const limit = parseInt(options?.pagination?.limitStr);
|
||||
const nextToken = entities.length === limit && (parseInt(nextPageToken) + limit).toString(10);
|
||||
const nextPage: Paginable = new Pagination(nextToken, options?.pagination?.limitStr || "100");
|
||||
const nextPage = this.nextPage(options.pagination, entities.length);
|
||||
logger.debug(
|
||||
`services.database.orm.postgres.find - Query Result (items=${entities.length}): ${query}`,
|
||||
);
|
||||
@@ -241,6 +238,14 @@ export class PostgresConnector extends AbstractConnector<PostgresConnectionOptio
|
||||
return new ListResult<EntityType>(entityDefinition.type, entities, nextPage);
|
||||
}
|
||||
|
||||
nextPage(pagination: Pagination, entitiesLength: number) {
|
||||
const nextPageToken = pagination?.page_token || "0";
|
||||
const limit = parseInt(pagination?.limitStr);
|
||||
const nextToken = entitiesLength === limit && (parseInt(nextPageToken) + 1).toString(10);
|
||||
const nextPage: Paginable = new Pagination(nextToken, pagination?.limitStr || "100");
|
||||
return nextPage;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
remove<Entity>(entities: Entity[]): Promise<boolean[]> {
|
||||
return Promise.all(entities.map(entity => this.removeOne(entity)));
|
||||
|
||||
Reference in New Issue
Block a user