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 can I declare a relationship with a SELECT statement?

I have 2 tables, iot_device and iot_device_status, where the status table saves all current and historical statuses of each device. I like to join the tables together as so: ``` SELECT i.id, i.name, data.lost, data.created_at FROM iot_device i INNER JOIN LATERAL ( SELECT * FROM iot_device_status s...

Find IDs from a list which do not exist in table

As the title says, i'm trying to filter a list of given IDs (could be hundreds) into a list of IDs that do not exist in a table (could have multiple thousands of rows). My research suggests that I should be doing something like this: ```sql select *...

With condition

I am using db.query to fetch some data with a lot of related data. One of the with statements is only applicable if a column value from another joined table is a certain value. Does with support a where that uses another joined tables data? If so, what does the syntax look like?...

Can Drizzle call RPC functions in the Database?

I could not find anything in the docs on the topic.

How to integrate Drizzle into Supabase project

Hey there, we're using Supabase for our project an unfortunately, it doesnt support transactional logic using their DB client. We are looking for an ORM that is easy to integrate to the existing Supabase-managed schema so we can run transactions using TS from our edge functions. How easy is it to setup Drizzle with an existing schema? Im managing migrations myself so Im more interested in getting all the good TS intellisense and typing directly in our Deno functions without having to now manage 2 DB libraries. Are there guides on how to do this?...

How can I derive the database type with schemas without instantiating it?

In our data service layer, we are looking to require a drizzle db parameter for our functions to accommodate multitenancy. However, we still want this parameter to be typed with our schemas. How can I achieve that?

Simple relational query in sqlite

I am trying to follow the documents but using BetterSqlite3. I have the schema shown in https://orm.drizzle.team/docs/rqb: ``` import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';...

How to avoid Inserting invalid values into a table with relations with mysql?

Using planetscale so I cant reference other columns My schema: ```ts export const mainTable = mysqlTable("main",{...

Cant drop key mysql

When adding a new key and pushing to DB, it will not allow you to drop the key and push to db.

Weird type errors when running code

Solution:
Disabled minifying and dts creation with tsup and it's not yelling anymore

Typescript enum to pgEnum

I have this code ```ts export enum field_types { numeric = 'numeric', text = 'text',...

Cast columns in relations

A great feature of drizzle's relational queries is that they don't actually require a foreign key, which provides a great amount of flexibility in querying your data. However, it doesn't seem like there is currently a way to cast the fields so that their types match. Something along the lines of ```typescript export const actionRelations = relations(actions, ({ many, one }) => ({...

Is there a simpler way to get an enum type than (typeof enumType)["enumValues"][number]?

Pretty quick question (and maybe quick answer) - we have this pattern in a few places and it looks a bit verbose.

Relational queries: many-to-many

How to exclude xId fields from findFirst | findMany method or i just need to use "Magical sql operator" :D. And can I get rid of the usersToStudios field? ```js...

After upgrading to 0.28.0 from 0.27.2, it is unable to infer the array type

Here is my schema definition: ```js const badgeTable = pgTable( "badge", {...

Is it possible to have nested values when doing a leftJoin?

```ts // returns nested results export async function getLoans(spaceId: string) { return db.query.loans.findMany({ where: eq(loans.spaceId, spaceId),...

How to separate Dev data from Prod data with one Postgres instance?

I'd love to use Drizzle with Vercel's Postgres Storage (Neon). On the Hobby plan, Vercel offers only one Postgres instance. I realize it's not a Drizzle specific question, but would love to know what's the easiest/best practice these days to separate Dev data from Prod data if all I have is a single Postgres instance? Any references to publicly available code examples would be hugely appreciated 🙏...

One-to-one relations

So, uh, I can't figure out why i keep getting this annoying message:
ERROR: could not identify an equality operator for type json at character 716.
ERROR: could not identify an equality operator for type json at character 716.
...

relations help

how can i have a many-to-many relation for example a user can have multiple followers and can follow multple users ```js export const users = pgTable( 'users',...

Do I need to close the DB connection after running a script using drizzle?

I have a very simple script to import some CSV data: ```typescript import { System } from "@foo/core/system"; import { readFileSync } from "fs"; ...