0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-20 22:12:38 -05:00

fix: add drizzle import

This commit is contained in:
bholmesdev 2024-01-18 11:37:19 -05:00 committed by Nate Moore
parent 23cfda80fb
commit e0c9f51259

View file

@ -1,6 +1,7 @@
import type { InStatement } from "@libsql/client"; import type { InStatement } from '@libsql/client';
import { getRemoteDatabaseUrl } from "../../utils.js"; import { getRemoteDatabaseUrl } from '../../utils.js';
import { z } from 'zod'; import { z } from 'zod';
import { drizzle } from 'drizzle-orm/sqlite-proxy';
const queryResultSchema = z.object({ const queryResultSchema = z.object({
rows: z.array(z.unknown()), rows: z.array(z.unknown()),
@ -9,8 +10,6 @@ const queryResultSchema = z.object({
export function createDb(appToken: string) { export function createDb(appToken: string) {
const url = new URL('./db/query/', getRemoteDatabaseUrl()); const url = new URL('./db/query/', getRemoteDatabaseUrl());
// @ts-expect-error Drizzle types should allow `rows: undefined` as a return value
// when `get()` is empty. Reported upstream.
const db = drizzle(async (sql, parameters, method) => { const db = drizzle(async (sql, parameters, method) => {
const requestBody: InStatement = { sql, args: parameters }; const requestBody: InStatement = { sql, args: parameters };
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
@ -25,7 +24,7 @@ export function createDb(appToken: string) {
}); });
if (!res.ok) { if (!res.ok) {
throw new Error( throw new Error(
`Failed to execute query.\nQuery: ${sql}\nFull error: ${res.status} ${await res.text()}}`, `Failed to execute query.\nQuery: ${sql}\nFull error: ${res.status} ${await res.text()}}`
); );
} }
@ -37,7 +36,7 @@ export function createDb(appToken: string) {
throw new Error( throw new Error(
`Failed to execute query.\nQuery: ${sql}\nFull error: Unexpected JSON response. ${ `Failed to execute query.\nQuery: ${sql}\nFull error: Unexpected JSON response. ${
e instanceof Error ? e.message : String(e) e instanceof Error ? e.message : String(e)
}`, }`
); );
} }