arreglar busqueda para queries extrañas

This commit is contained in:
Cat /dev/Nulo 2024-01-04 18:47:24 -03:00
parent f0798e8620
commit e890d5f63b
3 changed files with 7 additions and 9 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -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"
}
}

View file

@ -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 };