typeorm-paginator
Version:
TypeORM query builder pagination library.
26 lines (25 loc) • 1.46 kB
TypeScript
import { SelectQueryBuilder, ObjectType } from 'typeorm';
import { CursorPagination, Cursor, OrderBy, CursorTransformer, Nullable, Take, PromiseCursorPagination } from './interfaces/paginator';
export interface CursorPaginatorParams<TEntity, TColumnNames extends Record<string, string>> {
orderBy: OrderBy<TEntity & TColumnNames> | OrderBy<TEntity & TColumnNames>[];
columnNames?: TColumnNames | null;
take?: Nullable<Take> | number | null;
transformer?: CursorTransformer<TEntity> | null;
}
export interface CursorPaginatorPaginateParams {
prevCursor?: string | null;
nextCursor?: string | null;
take?: number | null;
}
export declare class CursorPaginator<TEntity, TColumnNames extends Record<string, string>> {
entity: ObjectType<TEntity>;
orders: [string, boolean][];
columnNames: Record<string, string>;
takeOptions: Take;
transformer: CursorTransformer<TEntity>;
constructor(entity: ObjectType<TEntity>, { orderBy, columnNames, take, transformer, }: CursorPaginatorParams<TEntity, TColumnNames>);
paginate(qb: SelectQueryBuilder<TEntity>, params?: CursorPaginatorPaginateParams): Promise<CursorPagination<TEntity>>;
promisePaginate(qb: SelectQueryBuilder<TEntity>, params?: CursorPaginatorPaginateParams): PromiseCursorPagination<TEntity>;
_applyWhereQuery(qb: SelectQueryBuilder<TEntity>, cursor: Cursor<TEntity>, isNext: boolean): void;
_createCursor(node: TEntity): Cursor<TEntity>;
}