Drizzle Team

DT

Drizzle Team

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

Join

Struggling with a GROUP BY count

with this query, ```typescript const data = await db .select({...

Is it possible to use .map and batch?

``` const prepared = [1, 2, 3].map((id) => db.select().from(Users)); const batchDynamic = await db.batch(prepared); // TS Errors ❌ const batchStatic = await db.batch([db.select().from(Users)]); // Works ✅...

how to do one to many?

hello everyone i am having some problems doing a one to many relation and select on a post schema i have. for context i get this error when ever i try to make a query using the where and with
Internal error: TypeError: Cannot read properties of undefined (reading 'referencedTable')
Internal error: TypeError: Cannot read properties of undefined (reading 'referencedTable')
here is my select statement ``` const post = await database.query.posts.findFirst({ where: eq(posts.id, params.postId), with: { tags: true, links: true,...

error "Cannot read properties of undefined (reading 'endsWith') at defaultForColumn"

after running npx drizzle-kit push can anyone help please? my versions ``` "drizzle-orm": "^0.32.0",...
No description

Replacing hardcoded text value in `jsonb`

Hi everyone I have this data in my jsonb column of my Postgres database: ```json [...

Nested "with" queries infer type "any"

The types for my queries with relations, are not inferred, and instead are always typed as "any". So for example, what's mentioned in the docs... `const users = await db.query.users.findMany({...

Drizzle failed to parse an empty JSONB Array

so I have a query that calls ARRAY_AGG() function and the result of query returned the aggregated value since the aggregated column is a JSONB this results in Array of JSONB, but some of the row may return an empty json, ```...

Error when executing drizzle-kit push

I have a view in my db, debug-view here is the definition in the schema: ``` export const debugView = mysqlView("debug_view", { t: varchar("t", { length: 5 }), err: mysqlEnum("err", ['default','success','failed','error','exception','warn','info','important']).default('default').notNull(),...

migration problem

Hello everybody, this is my first time using drizzle and using an sql library for the first time. I was wondering why am I getting this error? `` [⣯] applying migrations...LibsqlError: SQL_INPUT_ERROR: SQL input error: table platforms` already exists (at offset 13) at mapHranaError (file:///Users/bobasafe/DevLink/Link-Sharing/linksharing/node_modules/@libsql/client/lib-esm/hrana.js:262:16) at HttpClient.batch (file:///Users/bobasafe/DevLink/Link-Sharing/linksharing/node_modules/@libsql/client/lib-esm/http.js:118:19)...

Count in relation selct

hello how to correctly do count from other table with condition in relation select. Attribute translationLanguageCount ```import { db } from "@/db/db"; import { operator } from "@/models/operator"; import { sql } from "drizzle-orm"; import { SQL } from "drizzle-orm/sql/sql";...

Determining successfully applied migrations

Hi there! I'm having trouble determining/mappingg successfully applied migrations (using drizzle-kit) in my migrations table to the matching migration in my codebase. Migrations are applying successfully, and I can see an equivalent number of rows in the migrations table to the number of migrations defined in my codebase, however none of the values in the hash column in the migration table match any values in my meta or migrations directory Am I missing something? How else can I determine which migrations have successfully applied?...

Realtime connection to the database

I am creating a chat application, the database stores chat messages and should automatically show real time data to all the subscribers of the chat room. Is there any way to achieve the described functionality with drizzle and postgres?
No description

Cannnot push and migrate and cannot figure out the issue. Help appreciated!

Reproduction here: https://drizzle.run/h5jnr6nxrqmid8dcjwf4pfb8 Try running it and youll get the error. PostgresError: there is no unique constraint matching given keys for referenced table "courseOfferingsTable" ...

error in production, using Vercel

My app is running fine locally, I also have a local migrations folder and schema but as I have deployed my project on Vercel it's erroring out that, ```tsx error: relation "users" does not exist at /var/task/node_modules/pg-pool/index.js:45:11...
No description

Marking Migrations

Hello all, I want to ask if it is possible to mark migrations as applied like in django ? https://docs.djangoproject.com/en/5.1/ref/django-admin/#cmdoption-migrate-fake ...

is it possible to use a query as a table? i.e. define a query and use it as if it was a view

this would be so I can define re-usable queries that are used by other queries as if it were a table.

NextJS PGlite Drizzle setup?

Any thoughts/examples on what a NextJS (app router), PGlite, Drizzle setup looks like? Seems a bit tricky getting it all to run on client in NextJS with app router...

Type mismatch between tables from schema and drizzle-orm functions

I am getting an error for type mismatch while trying a simple db.delete(table) query:
Argument of type 'PgTableWithColumns<{...columns}, {}, {}>; title: PgColumn<...>; desiredWeeklyFrequency...' is not assignable to parameter of type 'PgTable<TableConfig>'
Argument of type 'PgTableWithColumns<{...columns}, {}, {}>; title: PgColumn<...>; desiredWeeklyFrequency...' is not assignable to parameter of type 'PgTable<TableConfig>'
.How can I fix this? These are the related files:```ts // schema.ts import { createId } from '@paralleldrive/cuid2';...

Get stuck when setting up Drizzle Kit from existing Supabase project

I have setup some basic config but Drizzle Studio have work for 1 time and now I can't connect it, just loading indefinitely Also when I was using instropect it stuck on fetching columns, enum. Appreciate if someone can assist me on setting up the project...
No description