Drizzle Team

DT

Drizzle Team

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

Join

Next.js, Drizzle and Supabase DB with transactions?

Hey, I really appreciate the value of transactions. They grant safety when handling multiple changes at once. I am setting up my Next.js project. I want to use Drizzle to handle my tables in my code....

Unable to modify data in drizzle studio

Error : Please add a primary key column to your table to update or delete rows. this is my package.json ```json "drizzle-orm": "^0.35.3",...
No description

All other relations drop when creating a new one

```js export const homologationSchemas = createTable( "homologation_schemas", { id: serialUuid(),...

Custom postgres JSON_AGG function help

I want to create a function simmilar to db.select that for JsonAgg. I also want to be able to do things like jsonAgg({...}).orderBy(...).filter(...).as(..) In my sql queries to make it more like the rest of the ORM. (I need these orderBy and filters optionally, and I know I can just pass them in as arguments but i'm trying to keep the api similar to how the rest of drizzle would implement a feature like this. I tried extending the SQL class function like this ...

Table type

In the example below, I have an abstract class with several methods. While redefining these methods for each implementation works, I want to provide default functionality directly in the repository as a static class attribute. This way, I can override the defaults only when needed. However, I’m unsure about the appropriate type for the table attribute. Can someone help me resolve this issue? ```ts export abstract class Repo<TEntity extends { id: string }, TInsert> { public abstract find(...

Auth.JS + Drizzle ORM ([auth][error] AdapterError)

I have been trying to complete the authentication setup , but this error keeps on popping up. I have followed all the installation part from the docs and configured google OAuth, and drizzleAdapter successfully. When a user clicks on signin, it creates the correct entry on the DB (both in users and account table), but it doesn't compelete the call. I have added logs in session under callbacks, and it is not called. And the session when logged in other files (although the DB is updated) returns a null....
No description

drizzle-orm not inferring type from soft relations

Hello, I have set up soft relations to products and prices, my schema looks like this: ```ts export const PriceTable = pgTable( "price",...

drizzle-seed TypeError: Cannot read properties of undefined (reading 'length')

this is the error im getting (any help would be appreciated!): ``` /node_modules/drizzle-seed/index.mjs:131268 && !values.every((val) => val.values.length !== 0)) { ^...

`The types of '_.config.columns' are incompatible between these types` when upgrading to Next 15

driver: turso drizzle-orm: ^0.33.0 Upgraded to Next 15 and now any usage of a table results in errors like this. I have another project where upgrading to Next 15 + Neon Postgres worked fine, so I'm not sure what's going on here. I'm deliberately using 0.33 due to an issue with Turso schema database migrations being broken in anything newer, so upgrading is not really an option (exhibits the same issue anyway). Not sure what Next 15 is doing that could potentially be causing this either, seems to just be a type issue as everything works at runtime. ...

DrizzleKit won't regenerate my schemas because of index keys

Hello, I have issue with my drizzle.config.ts. I tried to regenerate it but I keep getting this error even if I remove my docker container and uninstall drizzle-kit from my package.json. Error: We've found duplicated index name across public schema. Please rename your index in either the .....
No description

drizzle queries won't resolve

Guys, I am completely stuck with something after upgrading my drizzle-orm libraru version. This is the code I am testing: import type { DrizzleConfig } from 'drizzle-orm';...

Disambiguate optional one-to-one relationship

This is a similar problem to https://discord.com/channels/1043890932593987624/1084576896039260202/threads/1254869164607143998 - but instead involves two tables, one of which has a non-nullable foreign key to the other. https://drizzle.run/my887gq5kvpp1ogl3xpoe0zh I have table A that has an id column, and table B that has a nullable reference to table A on a unique column. This is an optional one-to-one relationship, however, there is another column on table B that is not unique and should have a many-to-one relationship to table A....

How to spy on Drizzle in Vitest to throw an error

Hi, I want to spy on a drizzle call in my vitest tests and use that spy to throw an error so I can test my error handling around the Drizzle call in my code should it fail. In the past I've done things like the below in Prisma but haven't had any luck replicating it with Drizzle yet and wanted to know if anyone else has managed to do something similiar. Ideally I want to just spy on a specific call update to a table (users) like in the example below. ```...

No such column Error - Query help

I'm struggling to figure out what I would think is a very basic query in drizzle... I can do it no problem in sqlite: ```SQL SELECT ab.user_name, ai.item, ai.trait, ai.guild, ai.rarity, ai.timestamp, ab.bid_amount, ab.use_case FROM auction_items ai LEFT JOIN (SELECT item_id, user_name, bid_amount, use_case FROM auction_bids WHERE user_id = "test_user_id" AND deleted == 0 GROUP BY item_id) ab ON ai.id = ab.item_id...

Recommended way for managing Postgres functions

Hi, I need to create multiple Postgres Functions, and they are very likely to change multiple times in the following days/weeks. I read that the recommended way is to create an empty migration file and add the sql there. That means for every change, I would need to create a new empty migration file. I was time about creating them on a directory with raw .sql files and creating them every time the project starts. With this way, a migration file isn't needed. ...

Adding joins to objects

Just a short post with a "yes it's a thing" or "no do it manually" Assuming I had a database with users and files, where each file has a user in the "owner" field, is it possible to select all users, but with a join which returns [{ name: "...", files: [...] }]...

Composite Keys and Unique Record ID's per User

Hey all, creating an app that multiple users can use to track items. They sign up and begin by adding items, item-locations and item-categories. I'm using NextJS and Drizzle plus Vercel-Postgres. I currently have tables for User, Item, Category and Location. Each of these tables has a unique primary key and all other tables except for user contained a link to User with user_id and a FK to users....

Unable to pass JSON array to PostgreSQL function jsonb[] parameter using execute raw SQL

When I run the following query I get the error PostgresError: malformed array literal: "[{"data":"test batch message 1"},{"data":"test batch message 2"}] ```typescript const msgs = [ { data: "test batch message 1" }, { data: "test batch message 2" },...

Vercel Postgres failed to work locally

I tried to use vercel postgres but getting the following error. It is working on the vercel deployment tho. [0] ⨯ 262 | // if (!newSet.has(issue)) { [0] 263 | // console.error(✅ ${displayName} fixed ${issue}`) [0] 264 | // } [0] 265 | // }...

How to use drizzle-seed to seed data?

I tried to use the drizzle-seed library to seed my local DB, but I get an error. Libraries I'm using: "drizzle-orm": "^0.36.4", "drizzle-seed": "^0.1.2",...