Drizzle Team

DT

Drizzle Team

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

Join

Schema in drizzle(pool, {schema}) doesn't work

I'm trying to add schema for the crud operations for my db. I'm adding schema to my drizzle() options but it does nothing (I'dont have any error inside index.ts file). I have to manually import all tables that I want to use. If I don't do that and insert table name anyway (no autocompletion from typescript) I'm getting an error: Cannot find name 'users'. Right now my code looks like this: // index.ts import { drizzle } from "drizzle-orm/node-postgres";...

Type of `tx` when using `db.transactions`

I want to use helper functions within db.transactions but I can't get the type of tx working so basically i don't know how to type tx in the updateUserNotifications function ```ts const updateUserNotifications = async ( userId: UpdateUserAttributes["id"],...

Update relationship within 1 query

is it possible to update relationships? for example i have a one to one relationship between users and notifications but i couldn't find any example of how i could update the notifications of a user in 1 query ```ts const updateduser = await db .update(users)...

getViewColumns function? (similar to getTableColumns)

Hello, in a situation where I need to join a view to a table. Here's the gist of my query code:
await db.select().from(myView).innerJoin(myTable, eq(myTable.someId, myView.someId));
await db.select().from(myView).innerJoin(myTable, eq(myTable.someId, myView.someId));
This works, however I'd like to be able to select only the view columns. For tables, we have the help of getTableColumns(), which is defined in the source code as:...

one to one query

I have a 2 models relation one to one, visit and visit_log, visit_log stores the visitId for reference to the visit table ```const result = await this.db.query.visit.findMany({ where: and(eq(visit.userId, userId)), with: {...

extract table names from db.query

Hi all, I want to extract the name of a table like this this.db.query however if I were to do this...

How does Drizzle Kit keep track of the migrations on PostgreSQL?

I don't see a ___drizzle_migration table or anything similar

implementing generics with crud and classes

I am trying to implement a base class, that could be overwritten/extended with the help of generics, but I am running into an issue with my create function, where I kinda get blown into generics hell the more I look at the type error. If anyone could help or just tell me that creating something like this is impossible please let me know haha. The issue I'm running into is in the create method where the values I'm passing in aren't happy with what it expects even though the Insert type is the inferred Insert of that specific table. Which doesn't make sense because update works as expected ```ts...

[SOLVED] When running a big bulk insert I get an error, MAX_PARAMETERS_EXCEEDED

I want to run a transaction that runs a large bulk insert but I get this error: ``` Error: MAX_PARAMETERS_EXCEEDED: Max number of parameters (65534) exceeded at toBuffer (/home/mast/workspace/work/mix-opt/dev/node_modules/.pnpm/[email protected]/node_modules/postgres/cjs/src/connection.js:181:20) at Object.execute (/home/mast/workspace/work/mix-opt/dev/node_modules/.pnpm/[email protected]/node_modules/postgres/cjs/src/connection.js:167:20)...

weird behavior with nextjs appdir experimental cache

I'm trying to use drizzle with planetscale's database-js inside of an unstable_cache (to leverage the tag caching system). ```ts export async function getArticles() { return await unstable_cache( async () => {...

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