Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/crud-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface CrudFilter<ID extends IdType = number, ROW extends RowType = Ro
offset?: number;
limit?: number;
projection?: Array<string>;
idLike?: string;
}

export interface CrudOperationsOpts<ID extends IdType = number, ROW extends RowType = RowType> {
Expand Down Expand Up @@ -239,7 +240,8 @@ export class CrudOperations<ID extends IdType = number, ROW extends RowType = Ro
if (!filter) {
return;
}
const { exclude, include, contain, leftContain, rightContain, fullContain, min, max, since, until } = filter;
const { exclude, include, contain, leftContain, rightContain, fullContain, min, max, since, until, idLike } =
filter;
if (exclude) {
for (const [key, value] of Object.entries(exclude)) {
if (canExactMatch(value)) {
Expand Down Expand Up @@ -291,6 +293,20 @@ export class CrudOperations<ID extends IdType = number, ROW extends RowType = Ro
}
}
}
if (idLike) {
Copy link
Copy Markdown
Contributor

@soomtong soomtong Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

임시 방편이긴 하지만 title 검색과 함께 매우 유용한 상황이어서 이해해주세요. @9w @TaehuiKim

const idLikeTrim = idLike.trim();
const start = Number(idLikeTrim);

if (!isNaN(start)) {
const idLikeLength = idLikeTrim.length;
const multiplier = Math.pow(10, 6 - idLikeLength);
const end = (start + 1) * multiplier - 1;

queryBuilder.whereBetween(this.columnName(this.idColumn), [start, end]);
} else {
console.warn('Invalid idLike value:', filter.idLike);
}
}
if (canExactMatch(min)) {
queryBuilder.where(this.columnName(this.idColumn), '>=', min ? min : null);
}
Expand Down