im getting problems with drizzle schemas

Hi everyone, I'm having a problem with the schemas, they all work except for transportistShema. If I add this one, I get the error TypeError: Cannot read properties of undefined (reading 'Symbol(drizzle:Schema)')
import * as giverSchema from './config/schema/cargoGiver.schema'
import * as transportistSchema from './config/schema/transportist.schema'
import * as userSchema from './config/schema/users.schema'

app.get('/', async c => {
const schema = {
...userSchema,
...giverSchema,
...transportistSchema
}

const db = drizzle(c.env.DB, {
schema
})

const res = await db.query.user.findMany({ with: { cargoGiver: true } })
return c.json(res)
})
import * as giverSchema from './config/schema/cargoGiver.schema'
import * as transportistSchema from './config/schema/transportist.schema'
import * as userSchema from './config/schema/users.schema'

app.get('/', async c => {
const schema = {
...userSchema,
...giverSchema,
...transportistSchema
}

const db = drizzle(c.env.DB, {
schema
})

const res = await db.query.user.findMany({ with: { cargoGiver: true } })
return c.json(res)
})
if i comment the schema like this, it works and idk why
const schema = {
...userSchema,
...giverSchema,
// ...transportistSchema
}
const schema = {
...userSchema,
...giverSchema,
// ...transportistSchema
}
No description
4 Replies
Yeaba_12
Yeaba_122w ago
First, make sure all your schema files are exporting their tables and relations correctly. Looking at your transportist schema file, modify the exports to be explicit
lucasp
lucaspOP2w ago
ty for answer, @Yeaba_12 how i should export my schemas?
Yeaba_12
Yeaba_122w ago
Make sure to export everything that's needed export { trailer, documentTransportist, unit, offer // ... any other related tables } and when importing and using the schema, make sure you're importing all necessary components and some thing like this in another file -> import * as userSchema from './config/schema/users.schema' import * as giverSchema from './config/schema/cargoGiver.schema' import * as transportistSchema from './config/schema/transportist.schema' and if you use node you can make it like this ->>> app.get('/', async c => { // Destructure and combine schemas explicitly const schema = { ...userSchema, ...giverSchema, ...transportistSchema, } const db = drizzle(c.env.DB, { schema }) const res = await db.query.user.findMany({ with: { cargoGiver: true } }) return c.json(res) })
Fedox
Fedox2w ago
I have the same issue. My schema is exported correctly because I can use tables in "standard" selects etc. When I try including any relation in the schema drizzle orm and drizzle studio start failing with this error I've managed to solve the issue by switching to relative imports from @/sth import style
Want results from more Discord servers?
Add your server