Drizzle Team

DT

Drizzle Team

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

Join

PG Array and drizzle-zod issues

Put a thread in the orm discussion before realizing it belongs here. https://discord.com/channels/1043890932593987624/1056966312997429278/1181343905732632687 Entirely possible I'm doing something wrong, but created an issue with a small reproducible example and seems like it might be a bug? https://github.com/drizzle-team/drizzle-orm/issues/1609...

Refactor transaction to batched expression

Im trying to refactor a transaction to a batched expression. I need help with basic sql concepts involving updating tables based on sub queries, and also drizzle syntax such as
sql`...`.as(...)`
sql`...`.as(...)`
. This is my current transaction to expire orders and release related stock: ```ts...

Updated drizzle-kit -> Error: Cannot find module 'drizzle-orm/pg-core'

I updated drizzle from: ```json "drizzle-orm": "^0.29.1", "drizzle-kit": "^0.20.6",...

Increment without first selecting

UPDATE table_name SET column_name = column_name + 1 WHERE condition;
UPDATE table_name SET column_name = column_name + 1 WHERE condition;
please any easy way to do this with drizzle? talking about the SET column_name = column_name + 1 part...

Libsql mapHranaError

Using Drizzle with Turso with the following schema and code and receiving a libsql error as shown. @libsql/[email protected] [email protected] [email protected]...
No description

Help with deciding when to use indexes.

I have the following schema: ```typescript // missing imports from drizzle to avoid discord character limit import { teamsTable } from "./clubSchemas"; import crypto from "node:crypto";...

DB operations don't execute when promise is not awaited

The following snippet will not actually execute the SQL update: ``typescript function setEmailVerifiedWithoutBlocking(id: string) { // If you replace void by await`, this works void db.update(myTable).set({ emailVerified: true }).where(eq(myTable.id, id))...

Transaction rolling back without error

Hello all, I'm trying to use Drizzle together with Supabase and SvelteKit to have transaction support. However, I've come across an issue which I'm having trouble understanding. The following query is successful on it's own (the value of the variables is extracted from a form data):...

Question about dynamic query building

Hello! I read this page here: https://orm.drizzle.team/docs/dynamic-query-building And I don't quite understand how to use it to merge wheres. I have this code and log:...
No description

Prepare statement throws type error for enums. How to get type safety for prepared values

the status column in the schema is an enum like so: ```ts status: mysqlEnum("status", "PENDING", "ACCEPTED", "DECLINED") .notNull()...
No description

Can I run the `migrate()` function exporting a raw SQL query in Drizzle ORM?

I am building a Tauri app with a local SQLite database, and I have access via JavaScript. Here's an example: ```javascript const result = await db.execute( "INSERT INTO todos (id, title, status) VALUES ($1, $2, $3)",...

bun:sqlite FindFirst returns an object with all values undefined

Running FindFirst gives me an object with the proper keys but all values are undefined. Running FindMany with a limit of 1 gives me the correct output but in an array. Enabling logger gives this output for both findFirst and findMany with limit 1 select "id", "name", "location" from "company" limit ? -- params: [1] I've narrowed it down by doing db.query.company.findFirst().prepare(); with this i can then do both .get() and .all(), it seems using get gives me the broken output while doing all give me the array with correct output. ...

On Failed Migration rollback doesn't happend on the database

If any migration file have multiple line of statement, and if 3rd line cause any error to failed the migration then changes made by 1st and 2nd line on the database did not rollback. so next time when i try to fix the issue of 3rd line and rerun the migration got error on 1st and 2nd line that those are already applied. reproduce code & more details: https://github.com/milon27/dirzzle-kit-error#error-statement...

Help with refactoring a (probably unnecessarily) huge query

the query is attached... too big for messages 🤣

circular foreign keys

I have separate files for each table: ``` export const productVariant = pgTable("product_variant", { id: serial("id").primaryKey(), defaultPackageSizeId: integer("default_package_size_id")...
Solution:
defaultPackageSizeId: integer("default_package_size_id").references(
(): AnyPgColumn => packageSize.id
),
defaultPackageSizeId: integer("default_package_size_id").references(
(): AnyPgColumn => packageSize.id
),
...

Postgres 'with' returns null with basic setup?

Hi all. Trying to get my head around Drizzle's query API but I've hit a stumbling block. I've got a basic team (has many) users schema, and have created a route that gets the user's current team. This is done with the following code: ``` const data = await db.query.users.findFirst({ where: eq(users.id, userId),...

avoiding conflicts in mySQL

Hi im trying to avoid conflicts in my app by checking the 'lastModified' column on the database against the client. But I also need to add successfully updated records to a status log table to record the history of changes. Because I'm using mySQL there's no way of returning specific rows effected. Is there a common approach for this? ```ts export async function updateStatusByIds({...

select and alter columns with drizzle-zod

Hi, I want to create validation schema for update patch request. Not sure how it should be done. I want to (based on drizzle schema) select which field is updatable and mark everyfield as optional. I tried: ```
const requestSchema = createDocumentSublineSchema.pick({...

How to create unique constraint on a column for a foreign key?

So I am trying to create a colours table, and a user should be able to add new colours with a unique name, but only for the tenant they belong to. For example, lets say a user adds "Blue" colour for tenant id 1, they can no now longer add "Blue" for tenant id 1, but they can for tenant id 2. How do I add this constraint at the schema level with drizzle. The reason I need this is because my app is multi-tenanted and I need to seperate the data between tenants, as I am only using 1 database and dont want users from another tenant to see data that isnt theirs....
No description

createInsertSchema does not infer notNull() correclty?

"drizzle-orm": "^0.28.6", "drizzle-zod": "^0.5.1", ```ts export const testTable = pgTable('accounts', {...