-
-
Notifications
You must be signed in to change notification settings - Fork 57
Labels
Description
New to SK, Drizzle, and my TS is weak too.
So I generated a new SK app with npx sv create whatever
and it generated this code in src\lib\server\db\index.ts
:
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import { env } from '$env/dynamic/private';
if (!env.DATABASE_URL) throw new Error('DATABASE_URL is not set');
const client = postgres(env.DATABASE_URL);
export const db = drizzle(client);
I was unable to use db
at all without errors IE: await db.query.user.findMany();
would throw TypeError: Cannot read properties of undefined (reading 'findMany')
.
I needed to use the following code... where I pass schema to drizzle.
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import { env } from '$env/dynamic/private';
import * as schema from './schema';
if (!env.DATABASE_URL) throw new Error('DATABASE_URL is not set');
const client = postgres(env.DATABASE_URL);
export const db = drizzle(client, {
schema
});
Hope this helps someone...