diff --git a/bun.lockb b/bun.lockb index b925de1..7e56ca4 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/sitio/package.json b/sitio/package.json index 184c06a..74677bc 100644 --- a/sitio/package.json +++ b/sitio/package.json @@ -39,6 +39,6 @@ "chart.js": "^4.4.1", "chartjs-adapter-dayjs-4": "^1.0.4", "dayjs": "^1.11.10", - "drizzle-orm": "=0.29.1" + "drizzle-orm": "^0.29.1" } } diff --git a/sitio/src/routes/search/+page.server.ts b/sitio/src/routes/search/+page.server.ts index 7471f1e..fcd96d4 100644 --- a/sitio/src/routes/search/+page.server.ts +++ b/sitio/src/routes/search/+page.server.ts @@ -1,19 +1,17 @@ import { error } from "@sveltejs/kit"; -import { eq, max, sql } from "drizzle-orm"; +import { sql } from "drizzle-orm"; import type { PageServerLoad } from "./$types"; -import { db, schema } from "$lib/server/db"; -const { precios } = schema; +import { db } from "$lib/server/db"; export const load: PageServerLoad = async ({ url }) => { const query = url.searchParams.get("q"); let results: null | { ean: string; name: string; imageUrl: string }[] = null; if (query) { - results = db.all( - sql`select p.ean, p.name, p.image_url as imageUrl from precios_fts f + const sqlQuery = sql`select p.ean, p.name, p.image_url as imageUrl from precios_fts f join precios p on p.ean = f.ean - where f.name match ${query} - group by p.ean;`, - ); + where f.name match ${`"${query}"`} + group by p.ean;`; + results = db.all(sqlQuery); } return { query, results };