Drizzle Team

DT

Drizzle Team

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

Join

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,...

Discussion: cuid2 vs ulid?

Is it better to have a sortable primayKey like ulid but leak the creation date? Or a non-sortable and slower one for enhanced security? Which is best for production apps? The section here in the docs references cuid2, but not ulid interestingly. https://orm.drizzle.team/docs/column-types/pg#constraints--defaults...

Ignore columns manually added in migration

Hey, is there a way to tell drizzle-kit generate to not touch columns added in migration manually. I've added manually some tsvectors columns, it is working fine, but when I am creating new migration drizzle-kit is adding DROP statements. Probably when https://github.com/drizzle-team/drizzle-orm/issues/247#issuecomment-1742110943 would be resolved I can create appropriate columns in schema, but for now I just want to tell drizzle to ignore them. Is there way to achieve that?

Drizzle typebox enum array not working

I am making this post to raise some attention to an issue I made around 2 weeks ago on GitHub. https://github.com/drizzle-team/drizzle-orm/issues/1345#issuecomment-1771082418 The typebox schema and types generated for enum arrays is wrong. It seems like it would be fairly simple to fix, I hope this can be investigated soon 😄...

Unable to use db.query but able to use reqular db.select

I had the problem with using Drizzle Queries, it isn't working but works with regular select my schema : ```js export const menuTable = pgTable('menu', { id: varchar('id', { length: 255 }).primaryKey(),...

Issue with DOM element types

When I install drizzle-orm to my NextJS app (app dir). It ruins typescript types of DOM elements.

Dealing with type safety

I am trying to do something like this: if (result.length === 0) { throw new Error(No user with id ${id} found.); }...

How to filter by a column in a related table?

Example: list all recipes with a specific ingredient Also, I wish to include all ingredients of each matched recipe in the response...