this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 62 lines 1.4 kB view raw
1import postgres from "postgres"; 2import { drizzle } from "drizzle-orm/postgres-js"; 3import { env } from "~/env.js"; 4import { relations } from "./relations.js"; 5 6const client = postgres(env.DATABASE_URL, { prepare: false }); 7const db = drizzle({ 8 client, 9 relations, 10}); 11 12export const DB = { 13 queries: { 14 getPokemonAtOffset: async (offset: number, limit: number) => { 15 return db.query.pokemon.findMany({ 16 columns: { 17 id: true, 18 name: true, 19 dexId: true, 20 }, 21 orderBy: { 22 dexId: "asc", 23 }, 24 limit, 25 offset, 26 with: { 27 types: { 28 columns: { 29 name: true, 30 }, 31 }, 32 }, 33 }); 34 }, 35 getFilteredPokemonAtOffset: async (offset: number, limit: number, nameFilter: string) => { 36 // Convert the filter to a SQL LIKE pattern (case-insensitive) 37 const likePattern = `%${nameFilter.toLowerCase()}%`; 38 return db.query.pokemon.findMany({ 39 columns: { 40 id: true, 41 name: true, 42 dexId: true, 43 }, 44 where: { 45 RAW: (pokemon, { sql }) => sql`lower(${pokemon.name}) like lower(${likePattern})`, 46 }, 47 orderBy: { 48 dexId: "asc", 49 }, 50 limit, 51 offset, 52 with: { 53 types: { 54 columns: { 55 name: true, 56 }, 57 }, 58 }, 59 }); 60 }, 61 }, 62};