Drizzle Team

DT

Drizzle Team

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

Join

Upsert create/update joined table similar to Prisma

Hey all, trying to get another one of my queries to migrate away from prisma. This one is a bit more complex. Trying to see if I am able to take a joined table and either update it or create it. Prisma has this as a nested option but I couldnt figure out how to solve this with drizzle. In the example below, I have a store that I want to update its joined table shelf or create it if its not there ``` await prisma.store .update({...

dynamic table name

how is that my code breaks:
const { tableName } = params;
const data = await dbPool.execute(sql`SELECT * FROM ${tableName}`);
const { tableName } = params;
const data = await dbPool.execute(sql`SELECT * FROM ${tableName}`);
...

Is there a way to call a prepared statement from within a transaction?

I have a prepared statement called p1. Is it possible to call it from within a transaction? Something like ```typescript...

Similar building of where clause to Prisma

I'm trying to migrate my prisma queries to drizzle but one thing I'm trying to do is convert the following. I'm lost on how best to 'build' a where clause similar to what prisma has depending on what properties I have passed into my function: ``` if (name) { whereClause.name = {...

How to add custom SQL queries during or after migration in drizzle schema?

Hi all. I would like to execute some SQL queries during (or after) migration. Is there a way how I can do it without calling SQL queries each time at application startup? In my use-case I am trying to make fixed partitions to improve performance, but that way can also be used to create custom and more complex indexes or event triggers.

Journal displays wrong driver (I think)

I've only been using drizzle for a little while and so far it was working great, however when I tried to rebuild my docker container i kept getting some (for me) unexplainable errors. Error: node_modules/drizzle-orm/mysql-core/db.d.ts(1,38): error TS2307: Cannot find module 'mysql2/promise' or its corresponding type declarations. I went and checked where in my project the string 'mysql' was used (maybe I accidentally imported 'drizzle-orm/mysql-core' instead of pg-core'. This wasn't the case and the only file in my project referencing 'mysql' was ./drizzle/meta/_journal.json, it has a first level key 'dialect', which is set to 'mysql'. From what I understand I should NOT alter these files directly since they are generated (right?). There for I checked my 'migrate' command...

Expected 1 arguments, but got 2.ts(2554)

Anyone know why I'm getting this type error? ```TypeScript await tx .update(transactionTemplateEntries)...

Bun with drizzle

I am attemtping to use bun with drizzle-kit and i Keep getting this error I am using planetscale mysql2 driver...
No description

Get raw query from toSQL

I trying to figure out if drizzle has a function or helper built in that builds the raw query returned from toSQL right now toSQL returns params and sql as an object, i would like to get the raw sql query this is what im doing now to achieve this, any alternatives or is there a something drizzle provides i missed thanks ...

error: Cannot find module "@libsql/linux-x64-musl" from "~/todion/node_modules/libsql/index.js"

error: Cannot find module "@libsql/linux-x64-musl" from "~/todion/node_modules/libsql/index.js"
No description

Updating with a subquery

Can I do this in Drizzle without the raw SQL? ``js db.execute(sql UPDATE feeds AS f...

MySQL Blob

is there support for mysql blob type?

Prepared Statement - Neon Syntax Error

Hi there, I am trying to use a prepared statement to run a query but am getting a syntax error. below you can see the .toSql() logged, as well as the error. ```...

many to many relation problems

I'm using planetscale and can't seem to figure out what is wrong with this relation. There's no autocompletion for with when using the RQB and trying to access the table manually throws an referenced table error ```ts // schema export const organizations = mysqlTable("organizations", {...

Getting typescript errors with latest version

I am currently getting this error when i upgraded to the latest version. The schema was auto generated by drizzle....
No description

Select data from related table as well

I have 2 tables: ```javascript export const foos = pgTable( "foos", {...

Subqueries with INSERT - errors

I'm trying to create an insert that uses a subquery ```ts const sq = db.select({id: orgs.id}).from(orgs).where(eq(orgs.publicId, input.orgPublicId)).as('sq'); const insertOrgResponse = await db.insert(orgInvitations).values({ orgId: sq.id,...

Postgres read slaves?

Is there a way to connect the orm to use a read slave for selects and master for writes?

Migrate using Neon and Sveltekit

this is my code ```ts import { pool } from '$lib/server/db'; import { drizzle } from 'drizzle-orm/neon-serverless'; import { migrate } from 'drizzle-orm/neon-serverless/migrator';...

Cannot find driver! mysql2 or pg.

I'm trying to run drizzle-kit studio can get this error: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'mysql2' imported from C:\Users\rober\code\projects\drizsup\node_modules\drizzle-orm\mysql2\index.mjs Here is my drizzle.config.ts: ...