Drizzle Team

DT

Drizzle Team

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

Join

Can i share drizzle transaction with knex.js's transaction (postgresql)

If i can do this, i'm able to gradually migrate from knex.js

Count filtered results

Hello, Is there a way to see the count for Filtered results?...

How to automatically run migration on NextJS start

The docs is not clear on how to do it. It still uses npx tsx src/index.ts which is a CLI command instead of runtime.
No description

Natively write SQL functions/triggers with Drizzle?

Is it possible to, for example, write this kind of logic directly in Drizzle's schema? ```sql -- Checks if a user already has an active ban before inserting a new one. CREATE OR REPLACE FUNCTION check_active_ban() RETURNS TRIGGER AS $$...

[SOLVED] "Not enough info to infer relation", many-to-many junction table w/ postgres

I have read the posts online that say you must define relation names on both sides, and I already did that, but it still isn't working. Can anyone else spot an issue here? I have a junction table representing a many-to-many relationship. The way it is organized in my schema can be seen in the following link, and the way I am trying to query it can be seen in the attached picture.
The TLDR of the schema: templateDefinition has many colorSets, colorSets have many templateDefinition. I want to query templateDefinition to include colorSets from the junction table https://gist.github.com/Connorelsea/76f12181ec4205533bdc4329970a6f66...
No description

Applying drizzle migrations on Vercel with Hono

Hi, I'm trying to apply that migrations on the directory like this: ```typescript await migrate(drizzleDb, { migrationsFolder: "./src/databases/tenants/migrations", })...

Unable to use `push` or `studio` anymore

Really no idea what happened but all of a sudden I'm getting this messages when trying to run any of those commands ```
drizzle-kit push
...

Using drizzle-kit push only works the first time (when database is empty)

I am using drizzle with supabase. I successfully pushed my schema for the first time but when updating it with new tables it hangs down in Pulling schema from database... To solve it I have to delete all the tables or intentionally make an error somewhere in drizzle config. Is this my issue or drizzle issue? I have been seeing similar cases but with no solution yet....

many to many help

Unable to create many to many relationship with junction table
No description

Orphaned Children tables after a successful migration

I was able to bypass sqlite constraint error by using PRAGMA foreign_keys option but it left my database in a corrupted state where children tables of ticket_order are referring to the temporary and now deleted ticket_order_old table ``sql PRAGMA foreign_keys=off;--> statement-breakpoint ALTER TABLE ticket_order RENAME TO ticket_order_old`;--> statement-breakpoint...
No description

Orphaned children tables after a successful migration

I was able to bypass sqlite constraint error by using PRAGMA foreign_keys option but it left my database in a corrupted state where children tables of ticket_order are referring to the temporary and now deleted ticket_order_old table ``sql PRAGMA foreign_keys=off;--> statement-breakpoint ALTER TABLE ticket_order RENAME TO ticket_order_old`;--> statement-breakpoint...

How to achieve a returning insert with relations

Hey so I noticed this is not currently possible, any advice on how I might be able to do this with the sql api? https://github.com/drizzle-team/drizzle-orm/issues/2325...

custom datatypes

Let's say I have
features: text().array().notNull().default(sql`ARRAY[]::text[]`),
features: text().array().notNull().default(sql`ARRAY[]::text[]`),
...

planetscale mysql serial col error

Any idea why using serial() within a column def throws an error?
No description

DefaultPostgresSchema?

Object literal may only specify known properties, and 'users' does not exist in type 'DefaultPostgresSchema'.ts(2353) âš  Error (TS2353) | Object literal may only specify known properties, and users does not exist in type . (property) users: PgTableWithColumns<{...

how to sort rows lexographically by the string value of the postgres enum column

I've read that postgres by default sorts rows by the integer value of enum columns and not their string value. Using drizzle orm how to sort rows of a postgres table lexographically by the string value of one of its enum columns?...

How to update/insert id of a reference when I have a different constraint

I am trying to update/insert a record that has an fk constraint on another table that has an id as the primary key, and a unique constraint on appId and code. At the time of update/insert, I only have the unique constraint. How can I update/insert the record without fetching the id? Something like this: ```ts...

Using drizzle in monorepo

I am building a project where I have 2 next.js applications. Let's call them admin and web. The admin is responsible for CRUD operations to database and allows the admin user to manage content on their website, while web interacts with the database in a read-only way, displaying the content for the user. I want to share a single drizzle db client between both projects because this keeps types for both projects synced and I don't have to write changes in 2 places whenever I want to modify something schema related. How can I achieve such a thing in a turbo monorepo or any other way?...

Calculating average of joined table column

I'm trying to achieve select/query, where DB would automatically calculate average rating for my contractor. Here are my two attempts, but both have some issues, when I'm also trying to fetch relations for contractor. ```Typescript // Gives error: PostgresError: column contractors.rating does not exist const anotherContractor = await db.query.contractors.findMany({ limit: 1,...

$returningId returning extra rows

Not sure if this is intended behaviour but with the mysql2 driver in drizzle-orm this:
console.log(await db.insert(table).values([row1, row2]).$returningId())
console.log(await db.insert(table).values([row1, row2]).$returningId())
Outputs...