Drizzle Team

DT

Drizzle Team

The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!

Join

Issue with Drizzle-Zod: Due to a type mismatch between the ZodObject and ZodType types.

I have issues with this part of the code "due to a type mismatch between the ZodObject and ZodType types. The ZodObject type is missing a readonly property that is required by the ZodType type": export type Media = z.infer<typeof updateMediaSchema>; export type NewMedia = z.infer<typeof insertMediaSchema>; export type NewMediaParams = z.infer<typeof insertMediaParams>;...
No description

Possible to reuse columns while selecting?

Apologies if this is documented somewhere and I've missed it I am currently in the process of transitioning from Prisma and follow this pattern quite often: ```ts...

Manually create migration file

Is it possible to manually create a migration file like the way prisma has it? basically just creating a sql file that is part of the migration but it does not get executed. I'm asking this because I want to create a migration file for a raw materialized view since views arent supported

How do you infer the type of a relations query?

I tried infer model and schema but it misses the relations created

Possible to select* off of Joined table?

Consider this SQL query ``` SELECT sb.* FROM books b...

ForeignKey Too Long

Hi Drizzle Devs ! I would like to know if you are working on the functionnality to customize fk naming because i can't fully migrate because my foreign key is too long...

Drizzle workflow on schema modification

Hi, can someone explain me the process to follow when we modify the schema to push modifications to database please. I'm working on 2 computers, and when i modify schema like adding constraints, when i go to my second computer, i run drizzle-kit introspect:mysql and push:mysql but no modifications are added, also if i drop my table and recreate it with drizzle push:mysl, constraints are not added to my tables....

Possible to have type from enum value?

Has you can see i am filtering all my users by type "clinician", supposedly its 100% sure that the output of this would be that the user type is "clinician", but it still picks up the other enum possibilities, is it possible to make it understand in the type inference that the user type will only be "clinician"?
No description

Creating join table that is simultaneously many-to-many and one-to-many

got a data modeling / sql question for you all: I have an entity A with either a many-to-many relationship to B, or a one-to-many relationship to C. There must be a unique ordering of all relationships from A to B or C, such that we can define an ordering such as B1, B2, C1, B3, C2... etc B and C are different entities, with wildly different table structures, and therefore cannot be combined into a single table. ...

Any way to replace null by undefined?

Before using Drizzle, I was using the type mapper and the transform option of postgres.js in order to transform undefined to null. That way, any inserted undefined would be inserted as null in the database, and any null value in the database would be an undefined in JS. I'm looking for a way to do this with Drizzle. AFAIU as I'm still using the postgres.js connector, I can continue with these options, so the issue is to use undefined instead of null in the types. Similarly to changing a column type with .$type<T>(). Thanks!...

Drizzle pagination with count

Hi, is there a way to have a paginated query that also count all posible results based on a condition? I have the following currently: `const result = await db.query.businessUsers .findMany({ orderBy: businessUsers.id,...

TRIGGERS in Drizzle

Is there a way to define/implement TRIGGERs in Drizzle? An example would be great!...

Migrating from Prisma Schema

I want to migrate away from Prisma, but I can't seem to find a good way to get the schema right: - Drizzle's introspect feature somehow generates garbage with VARCHARs deafult values, I saw that this seems to be a known issue on GitHub, so I suppose there is nothign I can do about that? - Then, while 1:1 relations seem to be covered, I can't get it to generate any (many:many) relations. How is that done by Drizzle? Does it use some kind of heuristics to detect relations? Our company's model has roughly 100 tables and for now we used Prisma to handle it, so we have a prisma schema in case that helps anything, but managing all relations manually is probably error prone and a bit of a problem. - Kysely has a nice generator to generate types from a Prisma schema. Can Drizzle also do that?...

[HELP]: I'm trying to re-create a CTE-insert in drizzle, having some difficulties

```sql with cart_products as ( select * from cart_product where cart_id = ${cartId} ) insert into order_product (order_id, cart_product_id)...

Add drizzle-kit check as a pre-commit hook

Is there a way to add drizzle-kit check as a pre-commit hook with husky that would actually prevent the commit if something is wrong with my migrations? Currently i can add it but it won't prevent commiting

Planetscale swapped the order of Primary Key Relation

Hey, running into this weird issue when using Drizzle push on a staging branch of Planetscale, trying to promote it to production In the screenshot you can see: - PRIMARY KEY (userId, serverId), + PRIMARY KEY (serverId, userId),...
No description

Postgres functions in the ORM?

Hello everyone, I'm learning typescript and SQL (with drizzle) and I'm trying to make an api endpoint that has something like this ``` const {name, owner, hidden, uuid} = updateServerDto; const upd = this.db.execute(...

InferModelFromColumns with columns defined with sql``

Let's say I have a select list that looks like this ```ts const defaultBookFields = { id: books.id,...

Issue with drizzle-zod?

Schema ``` export const testinArray = pgTable("testing_array", { id: varchar("id", { length: 14 })...

Optional One-to-One Relation

Currently it's possible to define only a One-to-One relation (https://orm.drizzle.team/docs/rqb#one-to-one) but in the types, the value returned will never be undefined or null. In my use case I would like to define a One-to-One relation that could be optional. Is there a solution? Is this even possible? (I also raised an issue on GitHub (https://github.com/drizzle-team/drizzle-orm/issues/1066) a month ago but I think it got lost there)...