icanflyit
icanflyit
Explore posts from servers
DTDrizzle Team
Created by icanflyit on 8/22/2024 in #help
Drizzle client nested schemas
Is there a way to nest schemas within the Drizzle Queries? I have my schemas multiple files in sub directories, and I export them in groups.
export * as paths from './schema/paths';
export * as reports from './schema/reports';
export * as auth from './schema/auth';
export * as paths from './schema/paths';
export * as reports from './schema/reports';
export * as auth from './schema/auth';
This helps with organization and works with the select and insert, but to use queries I have to spread my schema when passing it to drizzle. Ideally, I'd be able to query users like
await client.query.auth.users.findMany()
await client.query.auth.users.findMany()
vs.
await client.query.users.findMany()
await client.query.users.findMany()
Is this possible in drizzle?
1 replies
DTDrizzle Team
Created by icanflyit on 8/19/2024 in #help
drizzle-typebox loses typechecking when used from another package
I'm setting up a project with a monorepo (available at https://github.com/trilliumlab/trail-eyes-monorepo/blob/3459d8014508365d256db5cc8b088e880f8b29f6/) I have a separate package for the database that can be shared with all my apps. I use typebox throughout the project, so the database package uses drizzle-typebox and createInsertSchema to generate my typebox schemas. For some reason, it seems I lose typing from any schemas created with drizzle-typebox when I try to use them outside of the database package. This doesn't seem to happen with typebox schemas I create myself. What I mean by this is I have a file in my database that I setup to have a function that takes a drizzle-typebox generated schema, a function with a regular typebox schema, and a function with an object with a regular typescript definition (https://github.com/trilliumlab/trail-eyes-monorepo/blob/3459d8014508365d256db5cc8b088e880f8b29f6/packages/database/src/database.ts). I then try passing an empty object to these 3 functions and the inference works as it should. I then have a file in another package in my monorepo (https://github.com/trilliumlab/trail-eyes-monorepo/blob/3459d8014508365d256db5cc8b088e880f8b29f6/apps/scripts/src/db/import-routes.ts) This just calls the same 3 functions from above, but for some reason the first function shows no typescript error when I pass it {}, and other 2 behave as they should. I'm sure it's just something with my typescript configuration, but it's weird to me that it only happens with drizzle-typebox and not regular typebox schemas. If anyone had any input that would be greatly appreciated :)
4 replies