Drizzle Team

DT

Drizzle Team

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

Join

Recommended Docker Compose Workflow

Hey all, I'm new to making full stack applications and am working with Drizzle to make mine. I have a question on what the best practice is when using databases that are spun up using Docker Compose and how to initialize them with Drizzle tables. I have the following docker-compose.yaml ...

$count with relation api returning wrong values ( 2 instead of 0)

```ts async function findProjectById(id: number) { return await db.query.projects.findFirst({ where: eq(projects.id, id), with: {...

Is it possible to have conditional foreign key relation?

``` export const booking = pgTable( 'booking', { id: generateUUIDV4AsPrimaryKey(),...

Missing schema from generated SQL when using `.toSQL()` on a query style SQL query.

I'm trying to get use .toSQL() on a query (db.query.someTable) but it doesn't include the schema for the target tables. I want to use the .toSQL() to then pass the SQL and params to electric-sql to sync things I'm running drizzle on the browser. I didn't find the PGLite driver tag to use....

insert from select

I am trying to convert a SQL query like this to drizzle: ``` INSERT INTO table_name (name) SELECT...

Drizzle zod infer wrong type

Using createInsertSchema* with a jsonb field number | null for month is transformed into any...
No description

How to handle multiple unique constraints with onConflictDoUpdate?

My postgres table has 2 unique constraints:
unique("unique_game").on(table.idTeamHome, table.idTeamAway, table.time),
unique("unique_id").on(table.idEvent),

unique("unique_game").on(table.idTeamHome, table.idTeamAway, table.time),
unique("unique_id").on(table.idEvent),

...

Best practices for inferring types in queries?

I'm refactoring my app and I'm trying to keep my schema as the single source for my data types, at least for my model data. Inferring types has worked wonders for inserting and making basic queries. However, for more complex queries with nested data I've tried to make intersection types matching the structure of the query result, but ts doesn't like that (the structure might not be identical), and explicit casting doesn't seem to work either. ...

Already exits error

Hey, I am trying to build an application by using neondb and drizzle-kit. On my local, I can trigger that script npx drizzle-kit migrate without an error, but when my application's build process on the vercel, I am getting that error
No description

TypeScript Error

I'm running into a TypeScript issue with Drizzle ORM & SingleStore integration. Issue: I'm trying to define a table using singlestoreTable from "drizzle-orm/singlestore-core", but TypeScript is throwing types-related errors. Here's my schema: ...

Is it possible to run migrations on a local dev D1 db?

How do I run migrations on my local D1 when running wrangler dev?

Cant figure out how to converting a sql query to drizzle syntax

I've been trying to figure out how to convert this query for almost two hours, I don't understand how these multiple with statements translates into the drizzle syntax, anyone knows? ```ts WITH review_dates AS ( SELECT DISTINCT DATE(${ReviewLog.createdAt}) AS review_date...

PostgresError: type "vector" does not exist

Hello! A while ago I was creating a project with drizzle + pgvector. I created the generate custom by putting CREATE EXTENSION vector; But now it tells me that the extension does not exist. What am I doing wrong? Has there been any update? I'm still a bit new to vectorization, sorry!...

Unable to update because it is saying field does not exist in schema

I am trying to update the keyword field in stores however I am getting the following error:
Object literal may only specify known properties, and 'keyword' does not exist in type '{ name?: string | SQL<unknown> | PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>; }'.ts(2353)
Object literal may only specify known properties, and 'keyword' does not exist in type '{ name?: string | SQL<unknown> | PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>; }'.ts(2353)
...
No description

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()`...