Drizzle Team

DT

Drizzle Team

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

Join

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());...

Issue running migrate(): error: script "migrate" exited with code 1 (SIGHUP)

I am trying to run my migration script that should execute my migration sql files: ```import { drizzle } from 'drizzle-orm/postgres-js'; import { migrate } from 'drizzle-orm/postgres-js/migrator'; import postgres from 'postgres'; ...

How to select all from a table and get the the columns names returned as they are stored?

I want to do a select() query on my user table to get emailVerified: boolean('email_verified').default(false).notNull(), What is returning is emailVerified as opposed to email_verified. I want to return the latter, but also all the rest of the columns. ...

How to create unique lowercase index?

I'm trying to recreate the following sql statement. I don't think what I'm writing with the where clause is correct. But writing .on(sqllower(domain)) results in a type error. Is there a way to do it in drizzle currently? ```sql create unique index sso_domains_domain_idx on auth.sso_domains using btree (lower(domain)) tablespace pg_default;...

where filter returning typescript error when nested within a with

```js const disputedMatches = await db.query.active_members.findMany({ where: (active_members, { eq }) => eq(active_members.user_id, id), with: { match: {...
No description

Typing a helper function parameter to be a table with required column(s)

I'm having a hard time typing some helper functions where I need some params to accept any table as long as it implements certain required columns (key and type). Here's what i'm aiming for: ```ts export function withTranslation<T extends AnyTable, TT extends AnyTable</* How to type this to enforce certain columns, e.g. "locale"? */>>( event: RequestEvent | ServerLoadEvent, table: T,...