Use pagination by date
ci/woodpecker/tag/ociImageTag Pipeline was successful
Details
ci/woodpecker/tag/ociImageTag Pipeline was successful
Details
This commit is contained in:
parent
79a7e6c232
commit
a1d8e1ac97
|
@ -1,4 +1,4 @@
|
|||
import type { SelectQueryBuilder } from "typeorm";
|
||||
import type {SelectQueryBuilder} from "typeorm";
|
||||
|
||||
export function makePaginationQuery<T>(
|
||||
q: SelectQueryBuilder<T>,
|
||||
|
@ -7,36 +7,50 @@ export function makePaginationQuery<T>(
|
|||
sinceDate?: number,
|
||||
untilDate?: number,
|
||||
) {
|
||||
if (sinceId && untilId) {
|
||||
q.andWhere(`${q.alias}.id > :sinceId`, { sinceId: sinceId });
|
||||
q.andWhere(`${q.alias}.id < :untilId`, { untilId: untilId });
|
||||
q.orderBy(`${q.alias}.id`, "DESC");
|
||||
} else if (sinceId) {
|
||||
q.andWhere(`${q.alias}.id > :sinceId`, { sinceId: sinceId });
|
||||
q.orderBy(`${q.alias}.id`, "ASC");
|
||||
} else if (untilId) {
|
||||
q.andWhere(`${q.alias}.id < :untilId`, { untilId: untilId });
|
||||
q.orderBy(`${q.alias}.id`, "DESC");
|
||||
} else if (sinceDate && untilDate) {
|
||||
q.andWhere(`${q.alias}.createdAt > :sinceDate`, {
|
||||
if (!sinceDate && !untilDate) {
|
||||
if (sinceId && untilId) {
|
||||
q.andWhere(`${q.alias}.id > :sinceId`, { sinceId: sinceId });
|
||||
q.andWhere(`${q.alias}.id < :untilId`, { untilId: untilId });
|
||||
q.orderBy(`${q.alias}.id`, "DESC");
|
||||
} else if (sinceId) {
|
||||
q.andWhere(`${q.alias}.id > :sinceId`, { sinceId: sinceId });
|
||||
q.orderBy(`${q.alias}.id`, "ASC");
|
||||
} else if (untilId) {
|
||||
q.andWhere(`${q.alias}.id < :untilId`, { untilId: untilId });
|
||||
q.orderBy(`${q.alias}.id`, "DESC");
|
||||
}
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
if (sinceDate && untilDate) {
|
||||
q.andWhere(`(${q.alias}.createdAt, ${q.alias}.id) > (:sinceDate, :sinceId)`, {
|
||||
sinceDate: new Date(sinceDate),
|
||||
sinceId: sinceId,
|
||||
});
|
||||
q.andWhere(`${q.alias}.createdAt < :untilDate`, {
|
||||
q.andWhere(`(${q.alias}.createdAt, ${q.alias}.id) < (:untilDate, :untilId)`, {
|
||||
untilDate: new Date(untilDate),
|
||||
untilId: untilId,
|
||||
});
|
||||
q.orderBy(`${q.alias}.createdAt`, "DESC");
|
||||
q.addOrderBy(`${q.alias}.id`, "DESC");
|
||||
} else if (sinceDate) {
|
||||
q.andWhere(`${q.alias}.createdAt > :sinceDate`, {
|
||||
q.andWhere(`(${q.alias}.createdAt, ${q.alias}.id) > (:sinceDate, :sinceId)`, {
|
||||
sinceDate: new Date(sinceDate),
|
||||
sinceId: sinceId,
|
||||
});
|
||||
q.orderBy(`${q.alias}.createdAt`, "ASC");
|
||||
q.addOrderBy(`${q.alias}.id`, "ASC");
|
||||
} else if (untilDate) {
|
||||
q.andWhere(`${q.alias}.createdAt < :untilDate`, {
|
||||
q.andWhere(`(${q.alias}.createdAt, ${q.alias}.id) < (:untilDate, :untilId)`, {
|
||||
untilDate: new Date(untilDate),
|
||||
untilId: untilId,
|
||||
});
|
||||
q.orderBy(`${q.alias}.createdAt`, "DESC");
|
||||
q.addOrderBy(`${q.alias}.id`, "DESC");
|
||||
} else {
|
||||
q.orderBy(`${q.alias}.id`, "DESC");
|
||||
q.orderBy(`${q.alias}.createdAt`, "DESC");
|
||||
q.addOrderBy(`${q.alias}.id`, "DESC");
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue