Drizzle Team

DT

Drizzle Team

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

Join

Can't migrate to Xata, error: schema "drizzle" does not exist

Maybe a bug? Work fine with Neon but not Xata, Studio and Push command work great but with migrate I got error: schema "drizzle" does not exist here is my configuration ```javascript import { defineConfig } from "drizzle-kit";...

No type inference when specifying a reference.

Hi, I am trying out Drizzle for my application, and I am having some issues when I have a table that has a one-to-one and one-to-many relation on another table. I have the following schema: ```ts import { relations } from 'drizzle-orm'; import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';...

Next Js Docker Build step is failing because of DB connection

Anyone had this weird issue where the build command seems to need a db connection to successfully run? I've tried a variety of solutions but ultimately landed on this https://github.com/nextauthjs/next-auth/discussions/8996 anyone know a similar workaround but for postgres?...

How to type an optional included relation?

I'd like to implement a function that given an email returns a user. The function also gets an optional includeContacts boolean. When true, all user contacts should be returned as well. Here is what I currently have: ``` async function getUserByEmail(email: string, options?: { includeContacts: true }) {...

(Next)Auth.js Drizzle Schema

See https://authjs.dev/getting-started/adapters/drizzle#schemas for the Drizzle Schema provided I haven't been able to figure out how to get Auth.js schema working with drizzle. I believe the issue is handling the composite primary key In the example, the accounts, verificationTokens, authenticators primaryKeys are respectively...
No description

What it the role of the execute() function?

If I do not invoke the execute() function, the data is still saved in the database and returned. So, What is the role of the execute() function here?
No description

not able to run npx drizzle-kit studio

Hi all, When I am running the cmd npx drizzle-kit generate it's working fine but when I am using cmds like npx drizzle-kit studio and npx drizzle-kit migrate it's not working. TIA https://github.com/Boby900/yogurt...
Solution:
adding
import dotenv from "dotenv";
dotenv.config({ path: ".env.local" });
import dotenv from "dotenv";
dotenv.config({ path: ".env.local" });
in dirzzle.config.ts fixed it...
No description

Unable to query a table with another many to many relation

This seems to be an issue with the type handling, but it also could be an oversight on my part. I have 3 tables, let's call them A, B, and C. A and B have a one to many relation, and B and C also has another one to many relation. I have references to A from B, and references to B from C, but none from A to C. I'm trying to query B using db.query.B.findFirst({with: {C: true}), so I can get the C records of B. The inferred type of with ends up becoming {}, and as a result the response of tha...

Reference the same table

Hello, I use drizzle with a sqlite d1 database. I have the following schema: `export const authUser = sqliteTable("auth_user", {...

Table factory typescript problem

I have a basic table schema that all tables share (id, timestamps and more) and I'm trying to write an helper function that returns a pgTable with these fields already added. Right now it looks like this: ```ts const baseTable: PgTableFn = (tableName, fields, extraConfig) => pgTable( tableName, ...

Weird unique constraint

I'm trying to make a unique constraint on a column. It should also be case-insensitive (if there is one row with the value being "User", then "user" will be rejected) and allow non-distinct nulls. I can't figure out how to do this with drizzle-orm or sql. I appreciate any help. Thank you!

Not sure why we need to make relations when we have foreign keys?

After reading the docs, I understand that relations are a way to enforce some level of referential integrity on the application level as opposed to the database level. What I am confused about is whether I need to use them in order to make sure typescript is happy/to use the query api. Some clarity would be great on this as my first instinct is to completely forego the relations and just use foreign keys.

Auto reconnect to database

Hello, I am trying to auto reconnect to my PostgreSQL database. What is the best practice? ...

Next Js middleware error " ⨯ cloudflare:socketsModule build failed: UnhandledSchemeError: Readin":

Curren discussion: https://github.com/vercel/next.js/discussions/50177 The changes not working to me 😦 ```shell ⨯ cloudflare:sockets Module build failed: UnhandledSchemeError: Reading from "cloudflare:sockets" is not handled by plugins (Unhandled scheme)....

Drizzle-zod errors

What is supposed to be the highest version of drizzle-orm supported by drizzle-zod's latest release? I'm facing a breaking error when defining validation schemas using createInsertSchema with drizzle-orm@latest and it persists even when trying to regress all the way to @0.30.9, where I stopped trying older versions. ``` TypeError: Cannot read properties of undefined (reading 'Symbol(drizzle:Columns)') at getTableColumns (redacted/nodemodules/.pnpm/drizzle-orm@0.31.1@neondatabase+serverless@0.9.3_@types+pg@8.11.6_postgres@3.4.4/node_modules/drizzle-orm/utils.js:108:15)...

Dynamic column name and insert

Hi, how can I work with dynamic column names? I woud love to be able to do the following: ``` export const insertMultipleToJoinTable = async (...

NeonDbError: Error connecting to database

I got this error in connecting to my db on neon postgres, couldn't figure out why, I've tried both http and websocket connection to connect to my database, but nothing worked as expected, and also drizzle studio didn't work either, and I got this on error on drizzle studio "@Neondatabase/serverless' can only connect to remote Neon/Vercel Postgres/Supabase instances through a websocket"
No description

colBuilder.buildExtraConfigColumn is not a function

I get the above error when running drizzle-kit studio. ``` "drizzle-orm": "^0.31.1", "@neondatabase/serverless": "^0.9.3",...

Represent a table that contains an variants with strict keys (aka `Record` mapped type)?

I have a table that represents words (it's an English learning platform) where each word should have two examples (eg US and UK). How to display such a connection? This is not a repeater field where we can create many records attached to a word, but rather an already defined dataset with (in our case) two keys. ```ts export const word = sqliteTable('word', { id: integer('id').notNull().primaryKey(), name: text('name', { mode: 'text', length: 255 }).notNull().unique(),...