Drizzle Team

DT

Drizzle Team

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

Join

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...

Field type error on insert

I'm trying to insert data into my table, but I'm getting a type error. In my table, the expiresAt field is of one type, but when I insert it, it appears as another....
No description

schema in multiple files breaks types

I have split my schema into multiple files and exported them all like before with a single file. but now some of the types aren't working anymore and properties are missing/undefined on tables. if I place everything in a single schema again, it's working fine. I haven't changed any of the exports either....
No description

when running postgres in docker, drizzle cannot connect to it, says database doesnt exist

basically all i did is ./start-database.sh the env updated itself but it says that databse does not exist :/ i checked in docker desktop and the container is running

recommendation on changing data type of column?

what's the recommended approach here, e.g. changed from text -> double precision and I got this expected error error: column "time_waiting_for_builds" cannot be cast automatically to type double precision i'm wondering how to go around these kind of things. would editing the resulting migration sql be an anti pattern? is there a recommended approach to do these things?...

TypeError unless column is notNull

gave the following error. Object literal may only specify known properties, and <column> does not exist in type: schema.ts: ```ts...

Update returning with some relation

As the title says I am updating an object using this syntax: ```ts const idToUpdate = "someId"; const newEvent = {...};...

reference fails with Cannot read properties of undefined (reading 'id')

I have a foreign key reference that will not resolve. It seems that the other pgTable is undefined when it tries to resolve. I used madge to check and i have no circular dependencies. Does anyone have a strategy for how to find my error?

Drizzle not creating table

Hello, Do I need to manually create the tables? I have schema set up but its not creating the tables?...

Best way to insert thousands of records.

Hi, I've a use case where we get thousands of items from an API and I need to insert them into our DB. Right now my stack is node with nestjs+drizzle+postgres (aurora rds). As far I know the best option in PG for large inserts is to use COPY command....

using rqb with pgSchema

Trying to use rqb to access table within my "auth" postgres schema, but it seems that rqb hit the public schema I can access db.query.member even if member is within auth schema, definied with auth.table("member" , ...) Is there anything I'm missing ? difficult to find infos on how to perform query in this case on the doc...

How to specify types for raw sql statement?

How do I specify the types for a raw sql statement? I have the following code, but I have to override the types to unknown before I can get the types out. ```typescript interface SQLResults { numResponses: number;...

refine and createInsertSchema

createInsertSchema accepts and option to further refine the schema I would like to validate fields against each other like ensuring a completedAt field is date after a startedAt field. ```...

Changing postgres timestamp mode (string -> date) isn't reflected in migrations

Hi. I have my migrations generated and applied from my initial schema. Now in the schema I changed to mode: 'date' in multiple timestamp columns (ex: time: timestamp({ withTimezone: true, mode: 'date' }).notNull(),). This was mode: 'string' by default previously. Now when I run the drizzle-kit generate command, no migrations are generated. I made this change to multiple columns. ...

Conditional queries with $dynamic

Is there a way to not execute the query yet within the if statement? ``ts const countQuery = db .select({ count: sql<number>count(${recipeTable.id})`.mapWith(Number),...