Drizzle Team

DT

Drizzle Team

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

Join

What's the best practice for selecting an item only if a nullable field is not-null?

In this case, I have a type Patient which has a nullable field called stripeCustomerId. I create the patient earlier, and when I collect customer information, I add to it. Although, sometimes, I want to getPatient but I want it to throw an error if stripeCustomerId or another similar field is missing. I'd also like to handle errors in my getPatient function, so I don't have to handle errors everytime I call it. I created this, but I'm wondering if there's a better way. I'm still a novice....

Drizzle produces wrong branded type using Zod

It appears using brands with Drizzle Zod doesn't work correct? ```ts //? Files *// const fileIdSchema = z.string().uuid().brand<'FileId'>() type FileId = z.infer<typeof fileIdSchema>...

Unable to use db.query... functions

Following is the documentation for performing queries: import * as schema from './schema'; import { drizzle } from 'drizzle-orm/...'; const db = drizzle({ schema }); ...

Nested relation filtering

We have a user table (id, name, role…) and section table (id, name…), bridged by a user_section table (userId, sectionId). Hence, a many-to-many relationship. How can I accomplish in drizzle wherein I query for a section, including users (and its fields) under it, but only users with the role “Student”? Right now, I can only filter through userId and sectionId in the relational query API (see screenshot)....
No description

Drizzle ORM - Query on the same file

const users = (name: string) => pgSchema(name).table('users', { id: serial('id').primaryKey(), name: text('name').notNull(), invitedBy: integer('invited_by').references((): AnyPgColumn => users.id), });...

`drizzle-zod` and `z.nativeEnum()`

struggling to get drizzle-zod to work with z.nativeEnum after upgrading - as per the image, if i provide z.nativeEnum during createSelectSchema, it overrides all other types generated by drizzle-zod (see last 4 lines)
No description

[postgres] composite key does not result in constraint creation

i have this schema, and even though I've got a pretty basic composite primary key, whenever i go into a visual view of my db, no constraint is actually created. with other tables with single column pk's, it creates the constraint like ${tableName}_pkey, but in this case when i look on Neon there's no constraint here ```ts export const preferenceTable = createTable( 'preference', {...

Self referencing composite primary key table

I'm trying to define a table where each organization can define a parent-child set of locations. Each location has a composite primary key (org, id) but i can't seem to get the self referencing foreign keys to work. Is there a way to accomplish what i'm trying to do? here's my code. Thanks! ``` export const locations = pgTable( 'locations', {...

CORS error when trying to open Drizzle Studio with Supabase

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://localhost:4983/. (Reason: CORS request did not succeed). Status code: (null). https://localhost:4983/ just shows 404 Not Found I'm using "drizzle-orm": "^0.38.2" and "drizzle-kit": "^0.30.1". My browser is Firefox Developer and I'm on Linux. My Supabase database settings enforce SSL so not sure if that's related....

query where condition on foreign key relation

i have a table with a foreign key (one relation) to another table: ```export const mapRegions = sqliteTable( 'map_regions', { id: integer('id').primaryKey(),...

sqliteTable is deprecated

Apparently sqliteTable is deprecated and I couldn't find the replacement for it.

Drizzle Kit Schema Diff?

Is it possible to use drizzle kit to detect if there are schema differences, without actually applying them? I'd love to create a CI/CD job that looks at the production schema and blocks merging new code in until any schema changes have been published.

drizzle-zod is not sending custom message upon validation

I have created the following loginValidationSchema which I call in a validateData middleware inside my routes. I was expecting the custom error message to be sent to user whenever the user does not provide a value but it is not working \ zod-schema ```export const loginUserSchema = createSelectSchema(user, { email: (schema) =>...

Driver error callback

I'm trying to upgrade to 0.3.4 with the new drizzle client and am wondering how you are supposed to access driver callback events like 'error' or 'end'. My current code looks like this: ``` const pg = new pg.Client(...); const db = drizzle(pg, { schema }); pg.on("error", () => ...)...

Sequence problem with drizzle-seed

I'm experiencing an issue where after seeding data into a PostgreSQL table with Drizzle ORM, the sequence (users_id_seq) doesn't update to reflect the highest id inserted. Here are the details: Schema: ```export const users = pgTable("users", { id: serial().primaryKey(),...

Update column ONLY enabled when column is set as NOT NULL #3666

TL;DR: // Sharing this on Discord to find some help and explanation about the title. After the first problem that started as a discussion on github and not get any attention, I'm trying to reach you guys through discord....

Column not created even though appears in migration file

Hey team - I'm noticing a column that isn't created in my database, even though the schema + migration file clearly show that it is. Setup: - docker postgres running locally - drizzle-kit: "^0.28.0"...

Unexpected error happened 😕

```ts import { env } from "@/env.mjs"; import type { Config } from "drizzle-kit"; const path = "./src/server/lib/db";...
No description

Drizzle always says data exists even tho it can be undefined in ts.

export const selectRenter = async (name: string) => {
return db.select().from(renter).where(eq(renter.name, name));
};
export const selectRenter = async (name: string) => {
return db.select().from(renter).where(eq(renter.name, name));
};
This is my service....

Is this community still active?

For such a large OSS project with so many backers and users, it sure is quiet here.