Drizzle Team

DT

Drizzle Team

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

Join

Filter for articles with at least one comment

I am trying to migrate to Drizzle from Prisma and I am having issue with being able to query for all Articles that has at least one Comment as the title says. Here's a simplified version of my schema: ```typescript export const articles = sqliteTable("Articles", {...

How to get a similar result of db.query but with extra aggregation and using select

I have the following drizzle query which works correctly but the results is not what I expect since we are grouping votes as well by their ids. ```js export const mostUpvoted = await db .select({ id: feedback.id,...

Next 13, Next-Auth with Neon Postgres and Drizzle vs Prisma 5

I am trying to set up Next-Auth with Neon Postgres and Drizzle, but failing miserably. I set up a repo with several branches, including configurations for: 1) Next 13, Next-Auth, Neon Postgres, Prisma 5...

error: column "x" is in a primary key

I'm getting the following error, when trying to push my schema to my remote db: error: column "x" is in a primary key The weird thing is that everything works fine, when I drop all tables and run it for the first time, but if I try to re-run drizzle-kit push:pg, this is the error I get, even if the schema has not changed at all. Does anyone know what might cause this?...

postgres error: type "serial" does not exist

I want to migrate my my changes but i get this error: type "serial" does not exist. This is my schema: ```ts...

planetscale cache error

not sure if the issue is from drizzle or trpc, but trying to query the db via the RSC api fails with this error ```log result: { data: { secret: null,...

MySql 8 - How to use onDuplicateKeyUpdate with array?

as the title says, how do i use onDuplicateKeyUpdate with arrays? I can pass an array to .values() function but after that i have no idea how to handle duplicate. Help would be appriciated. thanks

Postgres json_agg

How can I create this equivalent using drizzle? ```sql select p.id,...

Performance difference between `.select()` and `.findMany()`

Is there any performance difference between .select() and .findMany() when using in prepared statements? Or any benefit of using one over the other? Which one is preferred in prepared statements?...

"VALUES(Column)" abstraction ( quick )

So, using MySql, I can use [insert query here].onDuplicateKeyUpdate({ set: { name: sql'VALUES(name)'}}). I was wondering though, if there's any abstraction for the VALUES function. On the site: https://orm.drizzle.team/docs/insert#on-duplicate-key-update, it only shows example to set an fixed value or the one that was already set - emulating "do nothing behaviour" - is there any abstraction for that SQL function?...

Prepared statement returns undefined

I have the following server action: ``` export async function getUserByEmailAction(email: string) { return await psGetUserByEmail.execute({ email })...

Prepared Update statements

Is it possible to use preparad statements for updating data? I was able to use prepared statements with .select(), .findFirst(), or .findMany(), but I am having trouble with .update(). If possible, what would the syntax be? I am trying to update a verificationToken, and I would need two placeholders there. Tried something like this, but It's wrong: ```export const psUpdateEmailVerificationToken = db.update(users).set({...

Schema to type

Hey guys, how do you make a schema item as a static type ? for example, this thing: ```ts export const orderItems = pgTable("orderItem", {...

db:push constraint is not found in the table

Hi, I'm using planetscale and trying to push to my db but I get the error: errno: 3821, sql: 'ALTER TABLE Subtopic DROP CONSTRAINT Subtopic_name_key;', sqlState: 'HY000',...

Does schema declaration filepath have to be exactly as in docs?

Hi there, I was just wondering: In the docs (https://orm.drizzle.team/docs/sql-schema-declaration) it shows a filepath of /src/db/*. Is it required to follow that filepath exactly, or is there a place you specify where to find your schema files?...

Slow api request using a transaction

Hi I wondered if I can remove async out of the child transactions inside the transaction function, to increase performacne or run promise.allSettled Use case is I have some code like this which works, but it is slow. ```...

tsc command fails when using sqlite

Hey, just started using the library, and I'm having issues running the tsc command. Here's the output (shortened a lot though): ``` node_modules/drizzle-orm/mysql-core/db.d.ts:1:38 - error TS2307: Cannot find module 'mysql2/promise' or its corresponding type declarations. 1 import type { ResultSetHeader } from 'mysql2/promise';...

Drizzle generates PG statement with parentheses on order by clause

Hello! I'm trying to execute a simple query with Drizzle, but it generates an invalid SQL statement. ```ts...

Streaming results from mysql

It seems like there have been a few unanswered posts about streaming results from a query, but they don't seem to be followed up on. Is that because there is an alternative solution to making these streaming requests rather than having drizzle support it natively? Any advice would be great....

Planetscale db:push has issues with default values

`` Warning You are about to execute current statements: ALTER TABLE comments MODIFY COLUMN created_at timestamp DEFAULT (now()); ALTER TABLE comments MODIFY COLUMN updated_at` timestamp DEFAULT (now());...