Drizzle Team

DT

Drizzle Team

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

Join

Help with improving database query

Hello, I am seeking advice on how to improve a database query I am currently working with. My objective is to get the data of a prompt using its ID, and this data includes the names of the tags associated with it.The currently way I am doing this works, but feels hacking so wondering if theres a more efficient way to achieve this, possibly through restructuring the database or altering the query itself. Below are the definitions for my "prompts" and "tags" tables from supabase DB: ```sql...

Typescript types for relational queries with neon db

Hey, I am having an issue with typescript types for relational queries with drizzle and neon db. Details: https://github.com/drizzle-team/drizzle-orm/issues/1204. Can anyone help me please?

Migrating in JS & JSON (no filesytem)

👋 we're big fans (and sponsors) of Drizzle at Val Town. We use it internally and love it. We just shipped an integration with Turso to give every Val Town user a SQLIte database, and I'm happy to report that I got Drizzle working in that environment! Integration: https://www.val.town/v/std.turso...

onDuplicateKeyUpdate

i'm having problems using onDuplicateKeyUpdate, doing it like ```js ...

Unable to generate uuid as primary key

Hey everyone! I've searched through the help posts with similar titles but I could not get the answer I wanted. I have a prisma current setup, and trying to switch over, but my uuid is generated as my postgres primary key but I keep getting the following error:
"null value in column \"id\" of relation \"User\" violates not-null constraint"
"null value in column \"id\" of relation \"User\" violates not-null constraint"
...

[Has Solution] Drizzle Studio says it's running on the server http://0.0.0.0

Idk what might be the issue. But when I run pnpm drizzle-kit studio. I am receiving the message: Drizzle Studio is up and running on http://0.0.0.0:4983 If I try to hit that route, nothing's on there. But if I instead change the URL to http://127.0.0.1:4983. It works....

Error using relational queries but not with core queries

when i do
const invitesData = await db.select().from(invites).innerJoin(members, eq(invites.inviterId, members.id)).where(eq(invites.invitedId, user.id));
const invitesData = await db.select().from(invites).innerJoin(members, eq(invites.inviterId, members.id)).where(eq(invites.invitedId, user.id));
everything works as intended, but when I do...

Is it good to use UUID as primary key ?

Hi, i want to define manually an id for my entry to be able to create at tame time a folder with same id. So using uuid can be a problem ? or maybe i have to get a normal id used for everything, and a uuid used to identify my entry in folders (for images) and for client supports ?...

What exactly i am doing wrong.. Prepared Query

```json [{ "error": { "json": { "message": "prepared statement "preparedConfig" already exists",...

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