Relational queries with planetscale - findMany etc undefined

Hey there! I am trying setup drizzle orm with relational queries with planetscale, but not sure how to debug this. I am following the docs on the setup for this, but after the setup it seems to not find the correct APIs. svelte kit Connection Setup :
import { drizzle } from 'drizzle-orm/mysql2';
import mysql from 'mysql2/promise';
/** schemas and env **/
const connection = await mysql.createConnection({
uri: DATABASE_URL
});

export const db = drizzle(connection, {
schema: {
...items,
...additionals,
...dishes,
...groups,
...recipes,
...requirements,
...locations
},
mode: 'planetscale'
});
import { drizzle } from 'drizzle-orm/mysql2';
import mysql from 'mysql2/promise';
/** schemas and env **/
const connection = await mysql.createConnection({
uri: DATABASE_URL
});

export const db = drizzle(connection, {
schema: {
...items,
...additionals,
...dishes,
...groups,
...recipes,
...requirements,
...locations
},
mode: 'planetscale'
});
Usage: Here I get a error - TypeError: Cannot read properties of undefined (reading 'findMany')
const result = await db.items.query.findMany();
const result = await db.items.query.findMany();
5 Replies
Asseater Peter
Asseater Peter16mo ago
Oh! I believe it's
db.query.items.findMany()
db.query.items.findMany()
Would you mind checking that?
Kamii
KamiiOP16mo ago
Aha! Now its screaming at items - TS2339: Property  items  does not exist on type  {}  in IDE, But in console it seems to still scream this for some reason even though I see in the IDE it finds the findMany api : TypeError: Cannot read properties of undefined (reading 'findMany')
Asseater Peter
Asseater Peter16mo ago
I think your schema is wrong here (tho I'm not sure, since I don't know what these items actually are) If the items in it are the table objects then you don't need to unpack them
Kamii
KamiiOP16mo ago
Ah you are right! This solved it The items are the table objects, thank you pepeLove
Asseater Peter
Asseater Peter16mo ago
Anytime.
Want results from more Discord servers?
Add your server