Drizzle Team

DT

Drizzle Team

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

Join

Is it possible to have a common transaction between prisma and drizzle?

I want to use drizzle and prisma within the same transaction.

update multiple rows with uuid id's

I found a great post by @Andrew Sherman from 2023 describing how to construct a case/when for updating multiple rows in one update. My id's are uuid, and a simple translation of his example (which uses integer ids), fails with the dreaded "operator does not exist: uuid = character varying" error. i've tried adding cast ( as uuid) in several places and can't seem to find it....

Counting many-to-many items

Hello, any suggestions how should I query for item and count the numbers of times it is referenced via many-to-many table? ```js const items = await db.select({ ...getTableColumns(A), countB: // count of B items on A...
Solution:
I ended up doing this: ```js const items = await db .select({ ...getTableColumns(A),...

Fetch data based on client's timezone.

Currently, I have a postgres db, where my timestamp data is being saved as a timestamp with timezone type, with +0 timezone. I've been fetching my data with the code below ``js const statement = sql WITH date_series AS ( SELECT generate_series(...

drizzle behind corporate proxy

is there an easy way to patch drizzles fetch to use proxy? (js)

Is there a way to create a unique constrain on a jsonb column in a table?

I have a table with a "label" column that is a jsonb column storing objects that look like this: { "en": "Girl", "ja": "女性" }. I would like to set up the unique constraint to ensure that each row is unique based on label->>en at least. Is this possible when defining the schema? Or do I need to restort to brute forcing it in the SQL? I am using Drizzle ORM with node postrgesql....

Is there a way to say a column value should come from another table?

I have the following two schemas ```ts export const seasonsTable = pgTable( 'seasons', {...

D1: `drizzle-kit push` says changes applied but database unchanged

Here are the logs: ``` ~/c/u/p/pin (main)> drizzle-kit push drizzle-kit: v0.23.0...

Are dynamic selects with type inference possible?

Title. I'm trying to add select statements conditionally. I'd like the function to return a properly typed query based on what I've passed. Is that possible? ```ts .select<SelectedFields<PgColumn, PgTable>>({ ...(opts.groupBy && { irrigationClientId: shrink.irrigationClientId }), shrink: sum(shrink.amount).mapWith(Number).as('shrink'),...

What will .array() do?

```ts export const users = pgTable('users', { id: uuid('id').primaryKey().defaultRandom(), fellows: uuid('fellow_ids').array(), createdAt: timestamp('created_at').notNull().defaultNow(),...

there is no unique or exclusion constraint matching the ON CONFLICT specification

Having this issue that I've seen others also getting, but without explanation. I'm only getting this error in production, not in my local dev environment. ```ts...

Type inference breaking in drizzle-orm 0.32.0 ?

I am trying to update a column called 'isEmailVerified'but TS keeps telling me that 'isEmailVerified' doesn't exist in the schema. Everything used to work fine in the previous version. ` const updatedUserId: { updatedId: number }[] = await this.db .update(users) .set({ isEmailVerified: true })...

Compostie primary key of a composite primary key

Hello! 👋👋 I have a table Accounts with id as primary key ` export const accounts = pgTable('accounts', {...

Alias values rows in insert with mysql

Hello 👋 The use of "VALUES()" is deprecated in "ON DUPLICATE KEY" statement when inserting multiple values. (source: https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html#:~:text=Note,of%20this%20section.) Now you have to alias values like that ...

Multiple primary keys error

Hey, im having problem with migration, got this error: [⣟] applying migrations...error: multiple primary keys for table "workShopRates" are not allowed Even tho i dont have multiple primary keys. Here is my schema...

i cant add more than 5-6 rows of data. is there a limit (using drizzle for d1 db)

hi folks, i want to dump a form data that is around 1200 rows, right now using db.insert(contactForm).values([{}, {}] i can only add a limited 3-4-5 entries at a time. is this a limitation with drizzle or d1? is there any other way to bulk insert data? thanks!...

Subquery not working

So as u can see in te pics I am trying to get first from a subquery the firstAvailableSlot. And than in the main query trying to get some doctor infos and only the availableSlots with same doctorId but getting error
No description

array of number returning strings

Hey, I've defined an array of number in my schema:
price: numeric('price', { precision: 10 }).array()
price: numeric('price', { precision: 10 }).array()
...
No description

how to use booleans in dizzle?

i have succesfully followed the drizzle docs on how to use booleans but i get a weird error: Type 'MySqlBooleanBuilderInitial<"isFeatured">' is not assignable to type 'PgColumnBuilderBase<ColumnBuilderBaseConfig<ColumnDataType, string>, object>'. The types of '_.dialect' are incompatible between these types. Type '"mysql"' is not assignable to type '"pg"'.ts(2322)...

Switched from bun to pnpm & now i have errors?

So i had all kind of issues with bun so i made th desicion to switch to pnpm. One of the scripts i'm written now has a type mismatches. Here is the error message: Argument of type 'SQLiteTableWithColumns<{ name: "users"; schema: undefined; columns: { id: SQLiteColumn<{ name: "id"; tableName: "users"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: false; ... 5 more ...; generated: undefined; }, object>; firstName: SQLiteColumn<...>; l...' is not assignable to parameter of type 'SQLiteTable<TableConfig>'. So i switch from bun driver to better-sqlite3. So SQLiteTableWithColumns & SQLiteTable? Huh? Anyone know what i have have wrong here?...
No description