Drizzle Team

DT

Drizzle Team

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

Join

How to define `PostgresJsTransaction` generic parameter based on schema?

Consider the following schema ``` import * as countrySchema from './schema/country'; import * as orderSchema from './schema/order'; ...

How can I verify a hash?

I want to run a function `export async function findUserByApiKey(apikey: string) { return ( await db .select() .from(user)...

How can I close connections after a query is done

When Hot-Reloading I get a bunch of extra connections, and eventually I run out of connections. This is on dev btw This may not be cause by hot reload, i am unsure when running SELECT * FROM pg_stat_activity; in Supabase ...

Is there a way to explicitly type certain drizzle results as `Array<T | undefined>`?

For example, I am making a query which I know will sometimes return undefined, since I am accessing a row that may or may not be present. I'm not sure how to type this such that I have type safety through the rest of the code to ensure that I never access properties without undefined checks. I'm aware of Typescript noUncheckedIndexedAccess but that will change the behavior of all arrays everywhere in my codebase, which I do not want. I just want the ability to indicate that a certain Drizzle select result will sometimes have no items returned. e.g. const [maybeExistingEntity] = await drizzle.select(.....).limit(1) now strongly types maybeExistingEntity where I would like the type to be T | undefined....

Is there a way to configure pg introspect to generate date rather than string inference columns?

My workflow involves writing migrations by hand outside of drizzle and using schema introspection to pull in changes. This works well except for date columns, which are always generated as mode: 'string' by default.

I've done db:generate and db:push, but nothing happens.

```typescript import * as dotenv from 'dotenv'; import type { Config } from 'drizzle-kit'; dotenv.config();...

Add the appropriate Drizzle types to a helper function?

I'm trying to build "dynamic" relational queries with the buildAndConditions helper function. Here's a TS playground: http://tinyurl.com/bdf9r4mn...

Weird webpack error with nextjs, libsql and pnpm workspaces

Hello there! 👋 I have a side project that uses drizzle with turso in a pnpm workspace with the following structure: ```...
No description

How do you structure your schemas?

Hi, how do you structure your schemas? I'm building a larger app, and the schemas are growing, so it doesn't make sense to have all tables in one schema. However, creating multiple schemas as multiple files (screenshot included) is also something that I'm not in favor of. ...
No description

Running concurrent queries

Hi so maybe this is more of a SQL question sorry if so. So I understand the benefit of transaction is to do all of those queries as a unit and you can roll back all the changes if one fails for example. I also understand you can add await inside the transaction requests if you need them to be dependant on each other. ...

How to handle partitions?

Hey there, I didn't see any mentions regarding partitioned tables in the docs. So if they are not part of the drizzle schema, how would I work with them? If they are not part of the schema, can I use drizzle migrations to manage them?

planetscale - removing uniqueIndex

Hey there, I'm trying to remove a unique index on planetscale but when I push my schema, it tells me the constraint is not found My change: ```diff...

Migration timing out in Next.js Route

I am building an app where I am provisioning user's their own databases in Neon. I am currently running into an issue where after I create the user's database and connect to it, I try and run the migrate function and it just times out. Not sure if I'm doing it incorrectly or not. I tried with two variations of the path to the migrations folder: ```await migrate(userDb, { migrationsFolder: path.join(process.cwd(), 'drizzle/user/migrations'),...

Shortcut for .returning()

Is there a shortcut for .returning() where there's only one table I'm selecting from? I write: ``` .returning({ id: userSchema.id,...

ExecutedQuery data question

what do these attributes mean when it comes to planetscale? it's quite confusing ```ts headers: string[]; types: Types; rows: Row[];...

db.batch is missing

Hello, so i am trying to send 2 db queries at once to reduce latency by reducing round trips to from the server to the db and for some reason the batch property is missing. I am using the latest version of drizzle as seen in my package.json. I have tried restarting my ts server and restarting my vscode but no luck. ...
No description

push command didn't update schema to my database (truso)

Hi everyone, I just add a new column called "deadline" to my schema (pic 1 and config file in pic2), and then run push command: ``` npx drizzle-kit push:sqlite No config path provided, using default path Reading config file '/Users/wujianwei/Code/Web Development 💻/tasks.org/drizzle.config.ts'...
No description

[pg] How do I make subquery in select()?

I wanna write a query like this in drizzle, but it doesn't seem like working ```sql SELECT books.*,...

Entity classes

Is it possible to have Drizzle automatically map returned entities to classes? We're looking at using Drizzle ORM but need classes to apply property decorators and automapper.