Drizzle Team

DT

Drizzle Team

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

Join

Drizzle Studio not working with bun

I had a basic project running with pnpm, then switched to bun and removed the dotenv package and its imports in /drizzle.config.ts. Now when I run bun drizzle-kit studio I get this error: /drizzle/drizzle.config.json file does not exist...

Union of schema with relations

This is code for my 2 tables where I am creating a new role and the adding its permissions ```typescript import { array, nativeEnum, string, union } from "zod"; import { createInsertSchema, createSelectSchema } from 'drizzle-zod';...

As Column Alias

Hello, I have this drizzle + sqlite (better-sqlite-3) + typescript function, however, it's failing on the part where I use a subquery in the main query. ```ts...

Migrations issues with Mysql2

Hi, I've some issues with the migrations system of drizzle-kit (specially when using Mysql2 adapter). When I executed the migration function from drizzle-kit, It return an error:
sqlMessage: "Table 'game_player_ban' already exists"
sqlMessage: "Table 'game_player_ban' already exists"
, and that's true. The migrations are created by the command
pnpm drizzle-kit generate:mysql
pnpm drizzle-kit generate:mysql
but in the .sql file there is any instructions like
CREATE TABLE IF NOT EXISTS
CREATE TABLE IF NOT EXISTS
and same for the foreign keys with the ALTER instruction. I saw that was implemented in the Postgres adapter but not for mysql (or other). Do you think it's normal ? Are any issues on github ? Thanks for reading and could you help me please ?...

Running complex migrations

I'm a little confused on how to run more complex migrations like backfilling or splitting tables. Say for a todo app I have a users table with columns id and todo_body. Now I want to split that table into separate users and todos tables to have a many-to-many relation. Currently we're using knex, so in the knex migration file first I'd create the new table, then backfill existing todos into the new table, then drop the columns of the existing table....

How do I type the `with` object part of a query builder if I extract it to it's own object?

I have a large with object that I reuse across multiple queries and I wanted to extract it to its own variable for reusing it. I typed this object with DBQueryConfig["with"] which seems to make typescript happy but the return type is not inferred correctly. Am I missing something? ```typescript const fullEventWithParams: DBQueryConfig["with"] = { users: {...

Does calling `drizzle()` multiple times on the same db client instance consume more resources?

related to a question from: https://github.com/drizzle-team/drizzle-orm/issues/594 Would using the same postgres(...) client instance and creating multiple Drizzle instances from it, e.g. one for each request in a middleware, consume additional database connection resources compared to creating one drizzle instance for the whole server process? @Angelelz this is related to the question you asked in the github issue. I believe my current implementation doesn't have this problem since it uses proxies, but I was about to refactor to call drizzle() once per request and want to make sure I'm not about to blow up my database!...

Is there a better way to extract Typescript types for use in function args than what I'm doing here?

export const client = drizzle(adminPgClient, { schema });
export type DrizzleClient = typeof client;
export type DrizzleTransaction = Parameters<Parameters<DrizzleClient["transaction"]>[0]>[0];
export const client = drizzle(adminPgClient, { schema });
export type DrizzleClient = typeof client;
export type DrizzleTransaction = Parameters<Parameters<DrizzleClient["transaction"]>[0]>[0];
...

Has JSON aggregation been added yet (analogous to Kysely?)

I added some jsonAgg... functions to generate raw SQL to helper utilities a while back, in order to generate arrays of nested json objects in aggregation. There was discussion of adding these as first-class drizzle functions, did that ever happen? Helpers source: https://gist.github.com/rphlmr/0d1722a794ed5a16da0fdf6652902b15...

Recommended place to add prepared statements

Where is the recommended place to define prepared statements? Does it make the most sense to define them in the schema file or at the service layer? Just generally I guess where is the best place to declare prepared statements? I was also just curious on the general threshold of query complexity to make creating a prepared statement worthwhile. How complex does a repeated query have to be in order to see a performance benefit from a prepared statement?...

Relational Query - how to call mapRelationalRow

I am trying to integrate drizzle orm with electric sql. I got pretty much everything working (with some hacks), the last remaining thing is live queries with relational queries. So my approach is the following: type RunLiveResult<T extends SQLiteRelationalQuery<any, any>> = T extends SQLiteRelationalQuery<any, infer R> ? R : never; ...

Drizzle query with where clause and primary composite key

Hello, I have defined a composite key and am now trying to run a drizzle query to lookup the event where that key exists. I have defined the following query, is this the fastest way to go about doing this lookup? Thanks! Drizzle Schema Table: ```ts export const scans = pgTable(...

drizzle-kit dry run / different in/out

Hello! I want to test the matching of my migrations to the schema code declarations: My questions (I'm pretty sure "no" is the answer to all, so it's just stuff that I think will be good to support): 1. is there a programmatic way to run "generate migration"? didn't find any docs about a js api from drizzle-kit (only types) 2. is there a way to run a "dry run" / a way to have different "in" and "out" dirs? (this is why I need to copy) 3. is there a programmatic way to parse a config file, change it and pass it to drizzle-kit? I currently. have two different configs with just "out" different (I import the original and override though...)...

Can't set nullable field back to null in drizzle-studio

drizzle-studio does not allow me to set an int column to null even when choosing NULL from the dropdown. It defaults to a 0 which then throws an error upon saving.

Prepared queries don't appear to be generated

I'm using Drizzle with Postgres.js, which should auto generate prepared queries. I have this query here ```ts const prepared = db .select({ response: customResponses.response }) .from(customResponses)...

Is it possible to pass sub query to `from`?

I have a db.select().from() and I need to pass a nested query into that from. ``` SELECT g.id, g.name, g.background_image, json_agg(p) as platforms FROM ( SELECT g.*...

Use `getTableColumns` with `groupBy`

I am doing a nested query and postgres is requiring that every column I select be in the group by, can I use the method getTableColumns in the groupBy, I've tried just calling the method and destructing. No luck, the error reads "must have a Symbol.iterator method that returns an iterator"

"Duplicate Index" - but no dupliacte index...

Hey there, I've HAD a duplicate index in one of my schemas: ```ts { tenantId, f0, f1, f2 }) => ({ myUniqueIdx: uniqueIndex('uniqueIdx').on(tenantId, f1, f2), myIdx: index('imyIdx').on(tenantId, f0, f1, f2),...