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

Querying PG table by JSONB field

hi! I can't find any reference on how to query a Postgress table by a JSONB field. Eg: I have a table ```ts export const authMethods = pgTable( 'auth_methods', {...

drizzle-kit push:mysql drops unchanged primary key & introspect:mysql fails hard

drizzle-kit version: 0.19.3 database: Planetscale drizzle.config.ts: ``` export default {...
No description

Support for SKIP LOCKED in Postgres?

This feature would be really helpful. I wold love to know the best way to do this right now as well. Thanks

VercelPostgresError - 'missing_connection_string': You did not supply a 'connectionString'

Hello everyone! So I'm getting the following error while trying to use the @vercel/postgres package with drizzle ORM ```txt...

Transaction + prepared statement

Hi everyone. I was wondering how to correctly use a prepared statement inside a transaction with drizzle-orm. I obviously first looked at the documentation with no success then went to the github issues and found the issue #952 (https://github.com/drizzle-team/drizzle-orm/issues/952). I prepared an answer but eventually found that I was quite off topic and I came here. 1) In his code (issue 952), I don't see the point of using a prepared statement: he prepares a statement each time the function is executed then executes it right away. From what I understand / think, the prepared statement should be a global (with placeholders if needed), then executed in the function. ```ts...

creating external types based on drizzle types

hey I'm trying to abstract some of my drizzle calls into seperate functions to refactor my code. How would I go about getting the type that my .values() enforces on the current table and replacing my data: any with that? ``` export async function createInvite(data: any) { const invite = await db...

Drizzle-orm dependencies missing during build

Hi all, Im using Drizzle for the first time and finally made it work locally. But when I tried to build and push my code to a AWS Lambda it's missing a whole lot of dependencies ? This is my config: ```drizzle-orm: 0.28.6 pg: 8.11.3...
No description

orderBy with variable column

Hey all! I'd like to explore the possibility to order a query by one of it's columns, but the column itself is inferred from a variable. What i've tried: ```ts // "categories" has 2 column, id and name...
Solution:
const sortField = 'name';

await db.query.categories.findMany({ orderBy: asc(sql.identifier(sortField)) });
const sortField = 'name';

await db.query.categories.findMany({ orderBy: asc(sql.identifier(sortField)) });
...