Drizzle Team

DT

Drizzle Team

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

Join

Circular Reference in Schema Relation

I'm trying the following: ```ts export const pages = pgTable("pages", { ...shared, // primaryMetadataId: uuid()...

Supabase [users.id]

I ran drizzle-kit pull to get my existing schema from Supabase. The schema output included the following ``` export const notifications = pgTable("notifications", { id: uuid().defaultRandom().primaryKey().notNull(),...

Making a simple dictionary

i have added DictionaryTitle and Dictionary on the schema and im lost T^T .... i want to connect them so when i click the title it should go in to a new page for the definition of that title is
No description

Error With types from Drizzle

Since i upgraded to latest version of drizzle i am not getting any types and alot of errors. Example:
Property 'config' is protected but type 'Column<T, TRuntimeConfig, TTypeConfig>' is not a class derived from 'Column<T, TRuntimeConfig, TTypeConfig>'
Property 'config' is protected but type 'Column<T, TRuntimeConfig, TTypeConfig>' is not a class derived from 'Column<T, TRuntimeConfig, TTypeConfig>'
drizzle-orm: "0.36.3" drizzle-kit: "0.28.1" ...

Migration Order Question

Hey team - I'm trying to understand migration order as I keep running into the annoying error
error: column "created_by_api_key_id" referenced in foreign key constraint does not exist
error: column "created_by_api_key_id" referenced in foreign key constraint does not exist
...

What type to use for a batch item

I'm trying to type the array used to hold queries to be batched with the batch API. ``` const queries: ??? = []; ...

serial('id').primaryKey() vs primaryKey() in extraConfig?

Are there any implications with marking a column as a primary key through the extraConfig argument as opposed to on the column definition? If I define a column like the following, everything seems to behave fine, but I do see that in the snapshot that drizzle marks the column as primaryKey: false and instead considers this a composite PK ```typescript...

Transaction Query Statements

In my database transaction, how can I have three query statements that is three round-trips, as one query statement that is one round-trip, to improve on performance? My queries are not related/similar data so from my understanding a Union won't work and currently batch statements are not available within transactions with Turso

malformed array literal when trying to insert a 2d array of strings

I am getting this error when trying to insert a 2d array of string into a .varchar().array().array() or a .jsonb() field. The error is: An internal error occurred.: malformed array literal: \"[[\"saddas\",\"dasdsad\",\"dadad\",\"sdasda\"],[\"123213\",\"1321312\",\"1231313\"],[\"111111111\"],[\"aaaaaaaaa\"]]\" It seems to me that drizzle is converting this array of arrays into this invalid serialized string. When I use .jsonb column type, the above is the error, when I use the varchar().arr...

Double 'where' clause in dynamic query overriding the original 'where' clause not combining

Hi I am using Drizzle to fetch some records: ```ts const query = db .select({...

Query API Returned Structure

Is there a way to change the structure of the result of the query API. Here's an example showing what it currently does, and what I'd like to do. ```typescript...

drizzle-kit generate throws SyntaxError: Cannot use import statement outside a module

I have been using drizzle alongside React Native, and everything worked great. Unexpectedly drizzle-kit generate stopped working - I built my app and after that it started throwing... It throws with the following error: ```...

creating a generic selection function

Hey all, I'm trying to extract some shared logic into a function that will generate a query based off an input selectedFields. I can't for the life of me figure out how to get the generic right, and it seems like this should be a fairly common use case: ```...

Conditionally throw error on D1 Batch Process

In Cloudflare D1, we do not have db.transaction and instead rely on db.batch. Cloudflare D1 rolls back if a statement in the batch errors. It is working ok, but I was wondering if it was possible to throw an error if a select returns zero results. E.g. checking if the user is owner of a certain record before proceeding into other updates ```typescript...

How to log out batch operations

I realized that even when I turn on logget to true when initializing a drrizle client, it won't log out queries batched together Does anyone know how to log out batch queries?...

Drizzle-kit won't connect to local neon database

Hi! I'm hosting a local neon database for development using docker (I followed this guide: https://neon.tech/guides/local-development-with-neon) but I can't connect to it with drizzle-kit (migrate, push, studio etc.). I think the issue is that the neon driver needs custom configuration to work. The proxy is not on port 443 which is default. It's also on an insecure http. Is it possible to customize the proxy configuration that drizzle-kit uses?...

Shared db across services

Hey folks - we have two services that need access to the same database (a client facing API and our web app). I don't really want to setup a monorepo. I think my best bet is to either setup a shared git submodule or a private npm package? What's the best approach here for creating this + running migrations? Rn I'm literally copying and pasting code across the projects and want something a little more put together and in sync. Thanks!...

Nested select in an insert

Hi, is there a better way to use nested select inside an insert than to just use the sql function? For example I have this function: ```ts static async upsert(idPerson: number, studyType: StudyType) {...

Running SQL statement manually for in-memory database

I have an in-memory sqlite database: ``` import { readdir } from "node:fs/promises" import path from "path"...

Infer insert model for select in "Insert into ... select"

Thanks for adding support for "Insert into … select". This is going to make FKs to internal IDs a lot less painful. I have plenty of use cases where all service interfaces work off external IDs (id) but to insert/update they will need to be mapped to internal IDs (iid). Here's a typical example where customer's external ID is resovled to its internal ID so it can be used in the relevant column of transaction table. ```ts...
Next