Drizzle Team

DT

Drizzle Team

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

Join

Reset database

I'm using Vercel Postgres and once, a while ago, I reset the database using some command like drizzle-kit push, maybe? IIRC, there was some sort of conflict and it was like, "Sorry, gotta start fresh." Which was fine with me. Sometimes I want to just reset the database but there doesn't seem to be an easy way to do it. How can I force a reset?
Solution:
There is nothing builtin :/ With postgres I do that: https://github.com/rphlmr/drizzle-vitest-pg/blob/main/test/setup.ts#L28-L32...

Date (de)serializing

Hi, how can I achieve that for data type "date" in postgresql I will be able to insert dates in string and they will be deserialized as Date data type when selecting? In Drizzle v. 0.29.3, this behavior was common: I could input dates as strings, and they would be deserialized into Date objects. However, now it seems that Drizzle requires me to either: Serialize the date as a string and deserialize it as a string, or...

Same API for multiple databases

Hello, I am exploring the possibility of a binding that works for different databases. I remember this post that @Andrew Sherman made on the T3 stack server
Totally agree that it's easier to do, and with Prisma abstraction, it's much simpler to achieve....

error while querying "Converting circular structure to JSON"

whenever i do a query on driver table, it just gives me following error ``` Converting circular structure to JSON --> starting at object with constructor 'PgTable'...

How can I get the Typescript return type of a drizzle statement?

```ts // How can I type the return type of this function? export function selectUserIncludingToken(userId: User["id"]): ?? { return db .select()...

Drizzle and Turso not showing live data.

I'm currently using Drizzle and Turso, and have an api to add data into my database. However, I am only getting the data that was in the table before I added new data. When I view on Turso I see the updated data, and when I view through Drizzle Studio I am also seeing the updated data, however when I try to use my api to see the data it returns old data. ```ts import { NextRequest, NextResponse } from 'next/server'; import { db } from '@/db';...

Not null must have default value as well?

Noob question. Does a "not null" value have to have a default value? For some reason it seems like the case. This insert snippet is not working. and giving me a Object literal may only specify known properties, and email does not exist in type and Object literal may only specify known properties, and first_name does not exist in type When I comment out phone and email from my schema/make them both nullable/add a default value it doesn't give me this error. ```ts async signup(dto: AuthDto) { const hash = await argon.hash(dto.password);...

Drizzle-zod typeerror when passing in pgtable

I keep getting a type error when trying to get the zod schema from the pg schema with drizzle: public.ts ```ts import { pgTable, timestamp, serial, text, pgEnum } from 'drizzle-orm/pg-core' export const TeamSubscriptionTier = pgEnum('team_subscription_tier', ['basic', 'team', 'enterprise']); ...

Unable to rename table

I'm attempting to rename ironclad_account_kills to ironclad_account_npc but I'm unable to. What might be causing this? ```...

Type safety on .set() method?

Hey folks - I was wondering if there is a way to get type safety when updating a row using the .set method? In the example below, updated_at is the table name, not the property name updatedAt. This code runs with no errors, but of course never updates the updated at because it doesn't exist! ```typescript const data = await db .update(verifications)...

Cannot call update on table hat uses datetime

I've recently started using drizzler and seem to be getting a conversion error (TypeError: value.toISOString is not a function) in when trying to update a a single varchar column, specifclly in mysql-core\columns\datetime.ts:57:16. Is there anyway we can work around this or have it patched? It makes using datetime completely useless....

ESLint Error when not using Drizzle

I currently have the Drizzle eslint plugin enabled and I get this error: Without .where(...) you will delete all the rows in a table. If you didn't want to do it, please use toastTimeouts.delete(...).where(...) instead. Otherwise you can ignore this rule hereeslintdrizzle/enforce-delete-with-where Thething is, toastTimeouts is not a Drizzle object but just a normal ES map (const toastTimeouts = new Map<string, NodeJS.Timeout>();...
No description

there is no unique constraint matching given keys for referenced table "users"

i get this error when run migration
PostgresError: there is no unique constraint matching given keys for referenced table "users"
code: "42830"
PostgresError: there is no unique constraint matching given keys for referenced table "users"
code: "42830"
...

RQB: Why is a where clause inside a many-to-many relation not allowed?

Say we have posts and tags. Every post can have multiple tags, but a tag can have many posts. So a classical many-to-many relation. Note: we have a junction table to store the relation posts 1-n postsToTags n-1 tag ...

PostgresError: Unable to check out process from the pool due to timeout

My local server keeps crashing for some reason. I have a query that retrieves some data for a table and 2 more queries that adds / updates data. Not sure why this timeout occurs. Any ideas? TIA! ``` unhandledRejection: PostgresError: Unable to check out process from the pool due to timeout at ErrorResponse (webpack-internal:///(rsc)/../../node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/src/connection.js:803:66)...

Conditional returning, returning wrong types

Condtionals in returning are not returning the correct types.
No description

Push error: This statement does not return data. Use run() instead

I just updated drizzle-kit to versions 0.23.0 and when I try to execute drizzle-kit push I get the following error: ``` TypeError: This statement does not return data. Use run() instead at Object.query (.../node_modules/drizzle-kit/bin.cjs:121780:54) at sqlitePush (.../node_modules/drizzle-kit/bin.cjs:124445:23)...

A more modular way to combine predefined query into a single transaction

Hello currently I write my query into something like this ```ts export const addUser = (data: InsertUser) => { return db.insert(users).values(data).returning();...

Inner joining and left joining the same table (aliased) causes the return type to be never

I'm getting a weird issue where if I make two table aliases for the same table and then inner join one while left joining the other, the return type of my query ends up being never[]. ```typescript const fromCompany = aliasedTable(company, "fromCompany"); const toServiceArea = aliasedTable(serviceArea, "toServiceArea");...

Any tips for using Drizzle without the schema declared via Drizzle syntax?

We are using Atlas for DB migrations, and therefore don't have the schema declared via Drizzle. Introspecting the DB has not been too accurate unfortunately. Some issues: BOOLEAN inferred correctly as numeric, could this be inferred as integer mode: "boolean"? (I think Prisma does this) Named foreign keys getting dropped. (not too important?)...