Drizzle Team

DT

Drizzle Team

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

Join

Utilizing Many-to-Many relationships

Yo, I'm trying to make sense of a the drizzle way to handling many-to-many relations, but can't seem to understand how to get the related object with one statement (like in a classing double-join query) could somebody give me an example of a query utilizing this relationship? for example - when setting up the example here: https://orm.drizzle.team/docs/rqb#many-to-many...

transaction not working for better-sqlite3

Doing this updates the name of user. I am expecting it to do nothing as rollback is called on the next line. ``` await db.transaction(async (tx) => { await tx.update(users).set({ name: "test" }).where(eq(users.id, 1));...

is there a reason why my row isn't being delete with CURRENT_TIMESTAMP

```js const deleted_matches = await db .delete(schema.matches) .where( and(...

How would one go about caching in next 13 app router with db data

Im trying to cache the db call, trying to avoid making an api endpoint for each query and utilize server actions or just in file db calls on RSCs but the calls dont seem to cache correctly. Does anyone have an example of doing this correctly?

drizzle-kit generate requires sudo to create directory and SyntaxError on index.cjs, Unexpected "?"

I'm currently getting the above error when trying to generate a migration or spin up drizzle studio: Bun 0.81 drizzle-orm: 0.28.5 drizzle-kit: 0.19.13...

Type error inserting 'new Date()' into 'time' type schema.

Driving me up the wall this a bit. my schema ```ts import { mysqlTable, serial, varchar, float, time } from 'drizzle-orm/mysql-core';...

drizzle asks for <table> `id` when doing insert

I guess the ID should be autogenerated by the database itself, but not sure why it's asking me to pass it as a value when doing ```ts // This throwns TS error saying that ID is missing const data = await db.insert(workspaces).values([ {...

Data factories

Is there a good way to add a data factory to Drizzle, so that I can add new users quickly for testing etc. (Ideally with being able to pass through relationship data as well).

Prepared Statement doesn't exist

"message": "db error: ERROR: prepared statement \"s114\" does not exist\n\nCaused by:\n ERROR: prepared statement \"s114\" does not exist"
"message": "db error: ERROR: prepared statement \"s114\" does not exist\n\nCaused by:\n ERROR: prepared statement \"s114\" does not exist"
Hi, I am making like a voting thing with many to many relationship, and this one is causing me a problem. ...

Help creating many to many (user has many followers, user has many followees)

is this the right solution ?! my first attempts was putting 2 fields on the users followers, followees and i was corrected to this code : cannot be loaded work says users relation is missing something ```...

Inconsistent transactions with Drizzle/Planetscale

I'm having issues with updating multiple records in parallel using Promise.all inside a transaction using Planetscale's serverless driver. I've created a minimal repro here: https://github.com/tomqchristensen/drizzle-ps-tx. The gist of it is that trying to update multiple records in parallel using something like this: ```typescript const updateParallelTx = async (n: number) => db.transaction(async (tx) => {...

ERROR: prepared statement "s9656" does not exist

Not sure why I'm getting this because I have no prepared statement. I thought it might have been a bug with relational queries so I tried a regular select too. Both of these result in the same error. ```...
No description

PostgresError: unrecognized configuration parameter "schema" when creating client for postgres-js

Getting the error when I add schema to the call drizzle(client, {schema}) using version "drizzle-orm": "^0.28.5", "postgres": "^3.3.5", Error goes away when schema is removed. ...

Does throwing a regular javascript error inside a transaction, roll back automatically?

Curious if I need to actually call tx.rollback()? Or if we reach a regular error, or lets say a Postgres error occurs at some step, will everything be automatically rolled back? Or do we have to always try catch and rollback in the catch/finally block?...

Drizzle join in a subquery results in ambiguous columns

This fails with id ambiguous error, since the orderedQuestions.survey_question.id reference in the field selection of the second query generates the sql as 'id' rather than 'survey_question'.'id' as it should. ```ts const orderedQuestions = tx .select()...

Schema Definition Performance / Best Practice

Is it considered bad practice to have one massive client / schema definition for my whole project that is imported everywhere, or should I be creating a client with small smaller sub-schemas for each module? are there any significiant performance benefits to the latter? My project has about 20 tables with relations and am running into performance problems in my development environment (nextjs takes a long time to build routes in dev mode). Is splitting out multiple smaller schemas something that is likely to help much?...

Is there a recommended way to find or create a record? (postgres)

I don't want to do an insert with ON CONFLICT RETURNING since I have triggers which fire on row update and can't have them be called without an actual row change.

Get plain typescript type from enum

Hi, I am working on a NestJS + Drizzle app and I have the following in my schema:
export const userPermissionLevel = pgEnum("permissionLevel", ["admin","moderator","user","banned"]);
export const userPermissionLevel = pgEnum("permissionLevel", ["admin","moderator","user","banned"]);
...

Can't build app due to missing dependencies with Drizzle

Hello y'all, very new to drizzle and while trying to use the quick start guide I ran into the errors pictured. I am running a Nodejs server compiling JS to TS, with Express. Currently all i have in the file is the basic express example and the basic Drizzle example yet I cannot compile. Any help is appreciated. I already made sure I had all required libraries as per the quick start guide. Thank you....
No description

Why does JSON configuration for drizzle-kit not require a dbCredentials?

Hello, according to https://orm.drizzle.team/kit-docs/overview#configuration. For both JS & TS of the configuration we are allowed to pass in a dbCredentials ``` export default { schema: "./schema.ts",...