Skip to content

Commit e43f328

Browse files
committed
fix: remove paginationUniqueKey option
1 parent e233c85 commit e43f328

File tree

4 files changed

+7
-38
lines changed

4 files changed

+7
-38
lines changed

src/Paginator.ts

+5-18
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export default class Paginator<Entity> {
5353
public constructor(
5454
private entity: ObjectType<Entity>,
5555
private paginationKeys: Extract<keyof Entity, string>[],
56-
private paginationUniqueKey: Extract<keyof Entity, string>,
5756
) {}
5857

5958
public setAlias(alias: string): void {
@@ -116,7 +115,7 @@ export default class Paginator<Entity> {
116115
builder: SelectQueryBuilder<Entity>,
117116
): SelectQueryBuilder<Entity> {
118117
const cursors: CursorParam = {};
119-
const clonedBuilder = new SelectQueryBuilder<Entity>(builder)
118+
const clonedBuilder = new SelectQueryBuilder<Entity>(builder);
120119

121120
if (this.hasAfterCursor()) {
122121
Object.assign(cursors, this.decode(this.afterCursor as string));
@@ -136,26 +135,14 @@ export default class Paginator<Entity> {
136135
return clonedBuilder;
137136
}
138137

139-
private buildCursorQuery(
140-
where: WhereExpressionBuilder,
141-
cursors: CursorParam,
142-
): void {
138+
private buildCursorQuery(where: WhereExpressionBuilder, cursors: CursorParam): void {
143139
const operator = this.getOperator();
144140
const params: CursorParam = {};
141+
let query = '';
145142
this.paginationKeys.forEach((key) => {
146143
params[key] = cursors[key];
147-
where.andWhere(
148-
new Brackets((qb) => {
149-
const paramsHolder = {
150-
[`${key}_1`]: params[key],
151-
[`${key}_2`]: params[key],
152-
};
153-
qb.where(`${this.alias}.${key} ${operator} :${key}_1`, paramsHolder);
154-
if (this.paginationUniqueKey !== key) {
155-
qb.orWhere(`${this.alias}.${key} = :${key}_2`, paramsHolder);
156-
}
157-
}),
158-
);
144+
where.orWhere(`${query}${this.alias}.${key} ${operator} :${key}`, params);
145+
query = `${query}${this.alias}.${key} = :${key} AND `;
159146
});
160147
}
161148

src/buildPaginator.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export interface PaginationOptions<Entity> {
1414
alias?: string;
1515
query?: PagingQuery;
1616
paginationKeys?: Extract<keyof Entity, string>[];
17-
paginationUniqueKey?: Extract<keyof Entity, string>;
1817
}
1918

2019
export function buildPaginator<Entity>(options: PaginationOptions<Entity>): Paginator<Entity> {
@@ -23,10 +22,9 @@ export function buildPaginator<Entity>(options: PaginationOptions<Entity>): Pagi
2322
query = {},
2423
alias = entity.name.toLowerCase(),
2524
paginationKeys = ['id' as any],
26-
paginationUniqueKey = 'id' as any,
2725
} = options;
2826

29-
const paginator = new Paginator(entity, paginationKeys, paginationUniqueKey);
27+
const paginator = new Paginator(entity, paginationKeys);
3028

3129
paginator.setAlias(alias);
3230

src/utils.ts

-14
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,6 @@ export function decodeByType(type: string, value: string): string | number | Dat
6969
}
7070
}
7171

72-
export function stringToBool(value: string): boolean {
73-
return value === 'true';
74-
}
75-
76-
export function stringToNumber(value: string): number {
77-
const result = parseInt(value, 10);
78-
79-
if (Number.isNaN(result)) {
80-
return 0;
81-
}
82-
83-
return result;
84-
}
85-
8672
export function camelOrPascalToUnderscore(str: string): string {
8773
return str.split(/(?=[A-Z])/).join('_').toLowerCase();
8874
}

test/utils/prepareData.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ function setTimestamp(i: number): Date {
99
return now;
1010
}
1111

12-
const balances = [1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2];
13-
1412
export async function prepareData(): Promise<void> {
1513
const data = [...Array(10).keys()].map((i) => ({
1614
name: `user${i}`,
17-
balance: balances[i],
15+
balance: i + 0.1,
1816
camelCaseColumn: setTimestamp(i),
1917
photos: [
2018
{

0 commit comments

Comments
 (0)