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 pagination with count

Hi, is there a way to have a paginated query that also count all posible results based on a condition? I have the following currently: `const result = await db.query.businessUsers .findMany({ orderBy: businessUsers.id,...

TRIGGERS in Drizzle

Is there a way to define/implement TRIGGERs in Drizzle? An example would be great!...

Migrating from Prisma Schema

I want to migrate away from Prisma, but I can't seem to find a good way to get the schema right: - Drizzle's introspect feature somehow generates garbage with VARCHARs deafult values, I saw that this seems to be a known issue on GitHub, so I suppose there is nothign I can do about that? - Then, while 1:1 relations seem to be covered, I can't get it to generate any (many:many) relations. How is that done by Drizzle? Does it use some kind of heuristics to detect relations? Our company's model has roughly 100 tables and for now we used Prisma to handle it, so we have a prisma schema in case that helps anything, but managing all relations manually is probably error prone and a bit of a problem. - Kysely has a nice generator to generate types from a Prisma schema. Can Drizzle also do that?...

[HELP]: I'm trying to re-create a CTE-insert in drizzle, having some difficulties

```sql with cart_products as ( select * from cart_product where cart_id = ${cartId} ) insert into order_product (order_id, cart_product_id)...

Add drizzle-kit check as a pre-commit hook

Is there a way to add drizzle-kit check as a pre-commit hook with husky that would actually prevent the commit if something is wrong with my migrations? Currently i can add it but it won't prevent commiting

Planetscale swapped the order of Primary Key Relation

Hey, running into this weird issue when using Drizzle push on a staging branch of Planetscale, trying to promote it to production In the screenshot you can see: - PRIMARY KEY (userId, serverId), + PRIMARY KEY (serverId, userId),...
No description

Postgres functions in the ORM?

Hello everyone, I'm learning typescript and SQL (with drizzle) and I'm trying to make an api endpoint that has something like this ``` const {name, owner, hidden, uuid} = updateServerDto; const upd = this.db.execute(...

InferModelFromColumns with columns defined with sql``

Let's say I have a select list that looks like this ```ts const defaultBookFields = { id: books.id,...

Issue with drizzle-zod?

Schema ``` export const testinArray = pgTable("testing_array", { id: varchar("id", { length: 14 })...

Optional One-to-One Relation

Currently it's possible to define only a One-to-One relation (https://orm.drizzle.team/docs/rqb#one-to-one) but in the types, the value returned will never be undefined or null. In my use case I would like to define a One-to-One relation that could be optional. Is there a solution? Is this even possible? (I also raised an issue on GitHub (https://github.com/drizzle-team/drizzle-orm/issues/1066) a month ago but I think it got lost there)...

Having Issues Pushing Database Schema

Hi I am getting this issue whenever I am trying to push the database schema. Any help would be greatly appreciated. ``` ❯ pnpm drizzle-kit push:mysql --schema=./Database/schema.ts drizzle-kit: v0.19.13 drizzle-orm: v0.28.6...

migration failed

code: ```js const migrationClient = postgres("postgresql://jer:admin@localhost:5432/test", { max: 1 }) async function main() {...

TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys')

I am attempting to run db push, but I am getting this error above^^ does anyone know what might be going on?...

Nesting sqlite drizzle into a deeper location in my ts app, difficulties with src/ vs dist/

Hey! I'm very new to drizzle and trying to set up a very small drizzle instance for a service that reads a whole pile of json files and acts as a simple read-only information store. I got most of the setup to work. I have it at a location ``` src/...

syntax highlighting not working

I reinstalled the node_modules multiple times and it didnt fix my problem. This isnt suposed to look like this does it?
No description

Prepare raw sql query (Postgres)

Hi, I need to do a recursive query, so I think I need to use the magic sql operator to build it. Is it possible to make a prepared statement this way? I haven't been able to find a way, but something like db.prepare(sql`...`) would make sense to me.

packing migration files with the library

hey there, I'm trying to use migrate inside from a library consumer (i.e I have a @mycompany/db-lib that has doMigration and from my internal dev-app, I want to do something like: ```ts import { doMigrate } from '@mycompany/db-lib' export const onMigrateClick = () => {...

Any way to invoke a SQL function?

For ex: lets say I declare a SQL function CREATE OR REPLACE FUNCTION do_something() how do i invoke this function using Drizzle's interface?...

How to include array literals in raw sql?

I have an input array used for an order by using the array_position function - rather than passing the array as a single param, the call to:
.orderBy(sql`array_position(${ingredientNames}, ${entity.name})`);
.orderBy(sql`array_position(${ingredientNames}, ${entity.name})`);
...

MySQL Table Schemas

I need to generate the following structure of tables: 1. Sales 2.Sales .......