mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-21 22:16:18 +00:00
arreglar busqueda para queries extrañas
This commit is contained in:
parent
f0798e8620
commit
e890d5f63b
3 changed files with 7 additions and 9 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 };
|
||||
|
|
Loading…
Reference in a new issue