Drizzle Team

DT

Drizzle Team

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

Join

UUID insted of ID

Hi, is it possible to replace the "serial" column with UUID generation instead of the standard auto-increment when creating a schema in MySQL?

Dynamic where query

With a relational query, is there a way to change the where query based on user input? In Knex.js, we could do something like this: ```knex('questions')...

Planetscale migration error

Hey guys, I was just trying drizzle with planetscale for the first time and I end up having this issue with migrator using planetscale serverless driver with admin privileges,...

Drizzle-kit can't load env file via t3-env

I'd like to use t3-env to validate my env variables in my Drizzle config file. I've tried importing t3-env in the config.ts file, but I'm hit with the error SyntaxError: Cannot use import statement outside a module in env.mjs, which I find odd since it is explicitly marked as an ES module. Other than this, t3-env works fine with drizzle-orm. Full Error: ```js Reading config file 'F:\Projects\PROJECTNAME\drizzle.config.ts'...

I need some guidance on joins

Hi I am using joins because it makes the most sense in my application, I was gonna try out the relations api but I want to work on my sql skills as well, so I have this schema and I am trying to understand how to get all teh tables returned in a single query here is the schema ``` export const items = pgTable('items', { id: uuid('id').primaryKey()...

Best way to run safe raw queries when only having access to the table name?

Hey I'm working a Drizzle adapter for a library. The Adapter API only has access to the db Drizzle instance and the table name, what's the best way to perform a SELECT * FROM table given only those two parameters? The sql operator works by passing not the table name, but the schema (which I dont have access to) so I tried sql.raw but it doesn't escape variables. I could escape them manually, but maybe there's an easier/better way.

InferModel including relations?

Hi, How do you use InferModel to obtain a type that includes relations? The results for an executed query has the inferred types but I'm not sure how to infer the type more generally?...

How to declare 1-to-0:1 relation between tables?

As the title says. The existing helper one seems to be for 1-to-1 relations. Thanks!...

How to suppress 'relation "x" already exists, skipping' logs during migration?

It's rather annoyingly clogging up my terminal, I know the tables already exist, but there doesn't seem to be a (documented) way to either suppress the messages or check the database version (and therefore not migrate if the DB is up to date). Any current way to do this?

many to many doc example

hello, i want to know how its possible to get the same value in the doc for many to many ?https://orm.drizzle.team/docs/rqb#include-custom-fields

Custom Function to Transform Subqueries is missing types

👋 So I am trying to write helper functions that are able to transform subqueries. The goal is to work around not having access either RPC's nor subqueries in select statements. A bit more context in this discussion: https://discord.com/channels/1043890932593987624/1085153354340114563/1116875363193192470 However using something like ```ts function transformWithSubquery<T extends WithSubqueryWithSelection<ColumnsSelection, string>>(subquery: T) {...

How to insert many rows with one-to-many relationships

I have 100+ rows I want to insert into an artists table, and at the same time insert each artist's songs into a songs table. Each song would be linked to the artist ID, but the artist ID would be generated by the query itself. Any way to accomplish this with Drizzle? Basically, I have data like this I want to insert: ```js [...

Drizzle migrations workflow with CICD and multi-dev teams

Hi! I'm looking into ORMs to use for my team in a new Node/TS project, and Drizzle has caught my attention. tldr: Is it possible to use Drizzle in a CICD pipeline to apply migrations? One thing that I don't have clarity on is how Drizzle would work in an environment where multiple devs are working on migrations concurrently. ...

Query from table with where clause NOT IN another sub query?

For ex: select * from TableA where email not in (select email from TableB); ?

how to empty a table (postgres)

What's the best way to programatically empty a database table? I'm using ``javascript const emptied = await db.execute(sqlDELETE FROM featured_salons;`)...

using in nest.js

What is the proper way to use in nest.js (or express). Should I create one single instance of db that should be exported (singleton instance), or the db should be created each time when needed? Is there somewhere a sample code when using with nest ?...

"bind message supplies 1 parameters, but prepared statement \"\" requires 0"

`` const results = await drizzleDb .select({ count: sql<number>count(*)` }) .from(calls) .where(...

POSTGRES_URL_NON_POOLING vs POOLING

I'm setting up postgres and drizzle to try to run some edge function. I'm reading these docs: https://github.com/vercel/storage/tree/main/packages/postgres If I understood correctly edge functions can't use pools so I should use the POSTGRES_URL_NON_POOLING url to connect, is that correct?...

Subquery in select

Hi, is it possible to use subquery in a select? I'd like to generate something like this ``` select "user"."name", "userAddress"."address", (select count(*) from "userLike" ul where ul."likerId" = "user".id) as "likeCount" from "user" ...

Error when running drizzle-kit generate:mysql

I have no clue what this means ```apache ...>pnpm drizzle-kit generate:mysql drizzle-kit: v0.17.1 drizzle-orm: v0.26.5...