diff options
Diffstat (limited to '')
| -rw-r--r-- | packages/trpc/lib/search.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/packages/trpc/lib/search.ts b/packages/trpc/lib/search.ts index d4130798..67348141 100644 --- a/packages/trpc/lib/search.ts +++ b/packages/trpc/lib/search.ts @@ -5,12 +5,14 @@ import { gt, gte, isNotNull, + isNull, like, lt, lte, ne, notExists, notLike, + or, } from "drizzle-orm"; import { @@ -245,6 +247,50 @@ async function getIds( ), ); } + case "title": { + const comp = matcher.inverse ? notLike : like; + if (matcher.inverse) { + return db + .select({ id: bookmarks.id }) + .from(bookmarks) + .leftJoin(bookmarkLinks, eq(bookmarks.id, bookmarkLinks.id)) + .where( + and( + eq(bookmarks.userId, userId), + or( + isNull(bookmarks.title), + comp(bookmarks.title, `%${matcher.title}%`), + ), + or( + isNull(bookmarkLinks.title), + comp(bookmarkLinks.title, `%${matcher.title}%`), + ), + ), + ); + } + + return db + .select({ id: bookmarks.id }) + .from(bookmarks) + .where( + and( + eq(bookmarks.userId, userId), + comp(bookmarks.title, `%${matcher.title}%`), + ), + ) + .union( + db + .select({ id: bookmarkLinks.id }) + .from(bookmarkLinks) + .leftJoin(bookmarks, eq(bookmarks.id, bookmarkLinks.id)) + .where( + and( + eq(bookmarks.userId, userId), + comp(bookmarkLinks.title, `%${matcher.title}%`), + ), + ), + ); + } case "favourited": { return db .select({ id: bookmarks.id }) |
