Drizzle Team

DT

Drizzle Team

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

Join

Using with NestJS and Zod

I'm trying to use drizzle-zod and nestjs-zod together to create Zod schemas and classes for insert and select. I mostly got it to work, even with Swagger! However, I'm running into a problem with one of the create schemas. My table is defined: ```ts export const addresses = pgTable('addresses', { id: uuid('id').defaultRandom().primaryKey(),...

Many-to-Many joins results in weird values

Hey, I am new to Prisma, switching here from prisma so I can use a typesafe orm with D1 properly. I am trying to return a many-to-many joined result: ```ts const teamedUser = await db.select().from(usersToTeams) .where(eq(usersToTeams.user, user.id))...

Is drizzle fully framework agnostic?

I saw a lot of people use drizzle in NextJS, but i didn't find a lot of information about usage in frameworks like Nuxt 3 or Sveltekit. Are there things that need to be done diffrently depending on the framework?

Typing columns based on Table

I'm trying to make a generic paginateQuery function that would let me pass in the table and then an array of only columns from that table would be accepted. Is there any way to do this with the Drizzle types? I feel like I have gotten close a few times but nothing fully gets there. Thanks! ```ts const getFilterSql = <TColumn extends AnyPgColumn>( filter: string,...

Does onConflictDoUpdate work with composite primary keys?

I have a model defined below: ```ts export const userDevices = pgTable( 'user_devices',...

Support for multiple with statements?

Is it possible to have multiple with statements? ``` const carriers = await tx .with(carrierTaskCount)...

use constant in between operator

Hello guys, Is there any way to use constant in between filter instead of column?...

Type error: Could not find a declaration file for module 'drizzle-kit'.

Any idea how to fix this problem? I try to run this: npm i --save-dev @types/drizzle-kit: npm ERR! Cannot read properties of null (reading 'matches')...

Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert

This is my account model ``` export const accounts = mysqlTable("accounts", { id: nanoid("id", {}).primaryKey(), userId: varchar("userId", { length: 25 }),...

Are default values not transferred over via drizzle-zod?

It seems like when I use a default([]) in my schema file that when I create a Zod object, I have to re-do the defaults?

Replace on Insert

I can see that there is a .ignore() option added to insert, but is there an equivalent .replace() or someway to flag it in the code? I'm doing an insert many by passing through an array of values (e.g. await db.insert(ActivityTable).values(values);) which is effectively an over write of existing data as well as new data...

Is there a way to modify the select() on an existing query ?

Let's say I have this query that I pass to a function
const query = db.select().from(myTable)
const query = db.select().from(myTable)
...

The inferred type of '<tableName>' cannot be named without a reference to '.pnpm/zod@3.21.4

I'm trying to use the drizzle-zod but I keep getting this error... Any idea on where it comes from ? Thank you !...

Migration failure on fresh DB

I'm currently experiencing a migration failure on a fresh Postgres DB with both postgres.js and node-postgres. It's complaining that an enum I have defined in my schema (which should have created already as it's in the generated migration) does not exist. ``` ⌛ Running Migrations ❌ Migration Failed...

Using Vercel Postgres and developing locally

To confirm, if I want to use Vercel Postgres in production and a local Postgres DB for development, is the best way to just conditionally import drizzle (and other platform specific stuff like sql) from drizzle-orm/vercel-postgres or drizzle-orm/node-postgres based on NODE_ENV? I see the sample Next.js project has been updated for Vercel Postgres: https://github.com/vercel/examples/blob/main/storage/postgres-drizzle/lib/drizzle.ts...

Custom Type interpreted as String

Hello everyone, I am having some issues with getting Drizzle to work with PostGIS, I am trying to have support for PostGIS's Point geometry. This is what I have setup ```typescript export type Point = { longitude: number;...

Can I use queryBuilder for inserts?

My scenario is that I want to read some rows from a database (prod), and generate a SQL file that we'd use to populate a local DB. I wanted to use queryBuilder (https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/pg-core/README.md#query-builder) since I wouldn't need to connect to a DB to generate the SQL queries, but seems like queryBuilder only supports select() at the moment. Do I need to connect to a local DB if I want to generate insert() queries?

I ran introspect:pg to initialize my schema, then created a new migration. How should I deploy this?

The remote database, right now, doesn't have the drizzle.__drizzle_migrations table. It'd be nice to have a way to know that the old migrations - the ones that were generated by introspect:pg and just reflect the existing state of the database - won't run. Is this the right way to look at it? Thanks!

Transaction rollback

Hello guys. Kind of dumb question but should I cover body of transaction in try/catch and call rollback explicitly? Here is an example. What will happen some query throws an error in transaction callback? ```sessionId = await db.transaction(async (tx) => { const [{insertedSessionId}] = await tx .insert(session)...