Drizzle Team

DT

Drizzle Team

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

Join

Primary and Replica Query Load Balancing

https://orm.drizzle.team/docs/read-replicas I have a setup for 1 primary and 1 replica. I have it configured similarly to the docs and can confirm that queries are going into the replica. The issue I have at the moment is that all queries are going into the replica, and I want it to be like 70% using the replica while 30% uses the primary. It seems like the configuration only allows weighted decisions based on replicas, not including the primary....

Is there a valid use case for being able to specify a relation name that points to a "wrong" table?

Example: ```ts export const firstTable = pgTable('first', { id: text('id').primaryKey(), });...

client does not exist in type "NeonClient"

Probably been asked a lot of times, but i get this error after copying directly from the docs. Argument of type '[{ client: NeonQueryFunction<boolean, boolean>; }]' is not assignable to parameter of type '[string | NeonClient] | [string | NeonClient, DrizzleConfig<Record<string, never>>] | [DrizzleConfig<Record<string, never>> & (({ ...; } | { ...; }) & { ...; })]'. Type '[{ client: NeonQueryFunction<boolean, boolean>; }]' is not assignable to type '[string | NeonClient] | [DrizzleConfig<Record<string, never>> & (({ connection: string | PoolConfig; } | { client: NeonClient; }) & { ...; })]'. Type '[{ client: NeonQueryFunction<boolean, boolean>; }]' is not assignable to type '[string | NeonClient]'....
No description

composite primary key migration fail

I am trying to add a composite primary key via a custom migration file. I ran drizzle-kit --custom --name=recipient-primary-key to generate a custom migration file. In that file i have the following sql ```sql -- Step 1: Rename the old recipients table ALTER TABLE recipients RENAME TO recipients_old;...

Dynamic select() query builder

With the .$dynamic() operator, we're able to double up on .where() and .limit() additions without erroring. However, we can't add on to the original select() query. Is there a way to do this to add new fields to an existing query being built?

Updating a date with the node-postgres adapter

I am trying to update a date value like this: ``ts await db .update(schema.order) .set({ completedDate: new Date() }) // same error with sqlnow()`...

Disambiguating relations

Hi guys, started using drizzle and love it but ran into an issue when moving from Prisma to drizzle with relations. I have two tables, Users and Classes. The user table has the fields id, name, username, email and role enum which is either student or teacher. The class table has the fields id and name. For the relations I want the class to have many students and many teachers and for the user they can be a teacher of many classes but only a student to one class. How can I create the tables and relations to reflect this? Any help would be appreciated...

How does drizzle calculate SQL execution time? I am using the mysql2 library

How does drizzle calculate SQL execution time? I am using the mysql2 library

How to mock DbTransaction in PGLite?

Hi guys! As titled, anyone knows how to mock db.transaction(()?

Drizzle and Cloudflare D1

I created a svelte repo using create cloudflare cli. I found ```ts...

Output drizzle schema to json or similar

So I have a postgres database that is basically my primary source of truth for nutrition and excercise data I want to sync this to my typesense instance (I can do this through postgres trigger) and to a sql lite file I store on my clients mobile devices for offline support. But my question is there anyway to get my postgres drizzle schema as json string or something like that so I can manage syncing the typesense collections schema when i update my drizzle schema with a custom script....

db.query not updating

Hey all! I recently refactored my schema to take advantage of the findMany and findFirst functions. These are my collectionsTable relations: ```export const collectionsRelations = relations(collectionsTable, ({ one }) => ({ author: one(usersTable, { fields: [collectionsTable.authorID], references: [usersTable.id],...

Handling errors in Expo

Im using the setup provided at https://orm.drizzle.team/docs/connect-expo-sqlite. While developing today I stumbled across an UNIQUE constraint error which was expected. When looking at the error in the catch clause I noticed that the Error was just a plain JavaScript Error which makes it hard to parse the errors and handle them correctly, example: Error: Call to function 'NativeStatement.runSync' has been rejected. → Caused by: Error code : UNIQUE constraint failed: column1, column2 at construct (native)...

unionAll in pgView

How can I use a unionAll in a pgView? I've included an example. https://drizzle.run/enckmzihpalip5k0a8ahp9he...

Time type query inconsistencies

I got two different queires: ```ts const result = await database.query.employeesTable.findFirst({ where: eq(employeesTable.id, employeeId), with: {...

Do I need to manually add indexes on foreign key columns when working with PostgreSQL?

Hello, Here's example schema: ```ts export const orderItems = pgTable('order_items', {...

trying to use $count withing query relational api

PostgresError: column projects.project_id does not exist ```ts const projectsInQueueWithDrizzle = await db.query.projects.findMany({ with: { matches: true,...

Cloudflare d1 on cloudflare pages functions

In the drizzle docs, the following code is mentioned to work with cloudflare workers but how do I make it work for cloudflare pages functions ``` import { drizzle } from 'drizzle-orm/d1'; export interface Env {...

Complex seeding tasks

Heyo, I am just transitioning to drizzle-seed, but I am struggling to replicate the power I had with my monolithic file of for loops. One example is we have a table called week_number_systems which holds things like ISO 8601, US Sunday etc. Then, we run a task to populate another table called week_definitions. The week definitions table has each row represent a week, and a week number system can have many week definitions (one to many). This is so that our app's schedule is dynamic, and can support any type of week. The week definition has a starts_at and ends_at, as well as a year and week (because 1 day, can have have a different week number or year as per ISO 8601 or US Sunday)....

Is it possible to seed nested referenced entities?

If I have three tables with a one to many relations: Agency -> Project -> Domain I see in the docs that with refine you can create references from one table to another: ```ts...