Drizzle Team

DT

Drizzle Team

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

Join

DefaultPostgresSchema?

Object literal may only specify known properties, and 'users' does not exist in type 'DefaultPostgresSchema'.ts(2353) ⚠ Error (TS2353) | Object literal may only specify known properties, and users does not exist in type . (property) users: PgTableWithColumns<{...

how to sort rows lexographically by the string value of the postgres enum column

I've read that postgres by default sorts rows by the integer value of enum columns and not their string value. Using drizzle orm how to sort rows of a postgres table lexographically by the string value of one of its enum columns?...

How to update/insert id of a reference when I have a different constraint

I am trying to update/insert a record that has an fk constraint on another table that has an id as the primary key, and a unique constraint on appId and code. At the time of update/insert, I only have the unique constraint. How can I update/insert the record without fetching the id? Something like this: ```ts...

Using drizzle in monorepo

I am building a project where I have 2 next.js applications. Let's call them admin and web. The admin is responsible for CRUD operations to database and allows the admin user to manage content on their website, while web interacts with the database in a read-only way, displaying the content for the user. I want to share a single drizzle db client between both projects because this keeps types for both projects synced and I don't have to write changes in 2 places whenever I want to modify something schema related. How can I achieve such a thing in a turbo monorepo or any other way?...

Calculating average of joined table column

I'm trying to achieve select/query, where DB would automatically calculate average rating for my contractor. Here are my two attempts, but both have some issues, when I'm also trying to fetch relations for contractor. ```Typescript // Gives error: PostgresError: column contractors.rating does not exist const anotherContractor = await db.query.contractors.findMany({ limit: 1,...

$returningId returning extra rows

Not sure if this is intended behaviour but with the mysql2 driver in drizzle-orm this:
console.log(await db.insert(table).values([row1, row2]).$returningId())
console.log(await db.insert(table).values([row1, row2]).$returningId())
Outputs...

Error when pulling from MySQL

I'm following the instructions on https://orm.drizzle.team/docs/get-started/mysql-existing and have just installed Drizzle Kit 0.25.0. However when I run yarn drizzle-kit pull, I get the following error: ``` /<path redacted>/node_modules/drizzle-kit/bin.cjs:30727 Request2 = class extends GlobalRequest { ^...

Get the count of a nested relation in findMany()

Is it currently possible to get the count of a nested relation in findMany() query? ```ts const data = await db.query.docs.findMany({ with: { articles: {...

How to `as` a table name

Hey 👋 , I have a parent query that use a table let's say A, and in this parent query it contains another query which will also use A, how in drizzle can I as the table name for the sub query ? The code would roughtly look like so:...

No overload matches call even with strict=true

Hello! I have the problem this issue describe https://github.com/drizzle-team/drizzle-orm/issues/2619 It seems that using strict=true fixes it for everyone except for me. Does someone have an idea why ? I made sure to reload my window after changing my tsconfig.json and it did make the error go away. here's my code & error, IDE highlights "id" on error. ```typescript...

Resolved: Need help with my multi column primary and foreign key table

Setup: ``` Turso / libsql, dialect is set to turso Versions: "@libsql/client": "^0.14.0"...

Edge runtime issues after upgrading drizzle-orm to v0.34.1

Hello! I am using drizzle with Next.js project that is hosted on vercel. One of the routes is using edge runtime. After upgrading from v0.33.0 to v0.34.1 I sometimes (not always) get INTERNAL_EDGE_FUNCTION_INVOCATION_FAILED from vercel when visiting that route. I create a new drizzle client for every request like this: ```ts import { Pool } from '@neondatabase/serverless'; import { drizzle } from 'drizzle-orm/neon-serverless'; const pool = new Pool({ connectionString: env.DATABASE_URL });...

Extremely weird behaviour

Apologies for the lack of better title. I have come across a weird behaviour where select().from(tablename) returns old and stale data. `...

Drizzle kit push and migrate don't match typescript schema

Hello, I'm having issues with both push and migrate commands with drizzle kit generating incorrect SQL based on my typescipt schema. Any help would be much appreciated! drizzle.config.ts ```ts import { defineConfig } from 'drizzle-kit'...
No description

bun documentation

I ended up resolving the issue myself but the documentation on bun:sqlite is pretty unclear about the fact that you have to install @libsql/client to do migrations and specifically it doesn't list that in the installation step. The error message if you don't have it installed also does not specify that installing @libsql/client will fix the issue and installing better-sqlite3 will not.

PgCore: QueryBuilder Issue

Has anyone come across this issue with QueryBuilder where if a subquery generated directly with a database connection (const connection = drizzle(client, { schema });) works but if a subquery generated with a QueryBuilder doesn't?

Subquery select without left join

Is it possible to select fields from a correlated subquery on a table without doing a LEFT JOIN? Drizzle keeps telling me that it needs to be in a JOIN, but I don't want to join.

InferSelectModel does not work with a view

I have a simple view defined as ```ts const qb = new QueryBuilder(); const ordinaryUsersQuery = qb .select({...

unable to use the `push` command

I keep getting this error. ``` adam@Adams-MacBook-Pro blackbird % pnpm drizzle-kit push No config path provided, using default 'drizzle.config.ts'...

Cant drizzle-kit pull with next.js from supabase postgres

Hello, trying to learn drizzle by connecting it to an existing supabase project (postgres), and need to pull the DB schemas into drizzle. My drizzle.config.ts: ``` import { config } from "dotenv";...