Drizzle Team

DT

Drizzle Team

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

Join

Omit not working for me

I am trying to use Omit to return the object with the id field removed:
export type Item = InferSelectModel<typeof items>;
export type ReturnItem = Omit<Item, 'id'> & {};
export type Item = InferSelectModel<typeof items>;
export type ReturnItem = Omit<Item, 'id'> & {};
...

Can't filter using 'query' when relation is one to one

Hello, I'm trying to use where filter on this query: ``` const qb = db.query.event.findMany({ with: { workoutSession: { where: eq(workoutSession.athleteId, userId),...

How can I get a type from SelectedFields<MySqlColumn, Table>?

Hi guys sorry to bother buy I'm trying to build a Repository Pattern with Drizzle and I stuck with a type. The interface with I came up is ```ts interface BaseRepository<T extends MySqlTable,...

Insert and Select Schema - Force to overide type , because types of Serials, boolean are unknown

Hello it's more a question than an help because i have find the answer In the previous version i didn't have the needs to override my Insert and Select Schema because it detected very well my types. (screenshot 1) Now if i delete my override i have an error of mismatching type. ( screenshot 2)...
No description

storing time?

Hello, how to store time in drizzle? If I store new Date(), does it handle timezone? Is it stored as utc or Unix milliseconds?

Making a column only allow letters and characters, including capitals

I am using Yup for my validation on the client side. For example the username field does this:
.matches(/^[a-zA-Z0-9]*$/, 'Username can only contain letters and numbers')
.matches(/^[a-zA-Z0-9]*$/, 'Username can only contain letters and numbers')
My user schema on the drizzle side is:...

How to use Query with relations ?

Hello, I'm encountering an issue when trying to execute a query with relations in my code. Here's the function I'm working with: ```ts async getOneWithRelations(id: string): Promise<AlbumWithRelationsResponse> { const { db, withErrorHandling } = this; return withErrorHandling(async () => {...

Trying to generate a short id via a random string function

Hi everyone, In my schema I have:
id: uuid('id').primaryKey().defaultRandom().unique().notNull(),
id: uuid('id').primaryKey().defaultRandom().unique().notNull(),
...

update a nested jsonb field

I have a table with a jsonb column that is something like this: ```js { foo: { bar: 'test'...

Is it possible to run javascript between database transactions?

In my authentication flow, I need to do the following things on signup 1. Check if user exists 2. Check if email verification token exists 3. If not, create new verification token ...

Weird number overflow behavior between two database types

So I've got two databases that I use when developing locally, one is a Planetscale database and the other is from a docker image mysql:8.0.31-oracle I'm transitioning from storing Discord snowflakes as varchars to bigints to make sorting faster and so I don't have to cast them, to do that I'm using the following custom type so I don't have to update everywhere in my codebase to use bigints yet: ```js const snowflake = customType<{...
Solution:
I am dumb salute For anyone else who runs into this problem, in your MySQL2 connection set supportBigNumbers: true ```ts...
No description

accessing related foreign tables via sql operator

Hi, I have three tables. A url table, a redirect table and a request table. The schema looks like the following, ```ts export const url = pgTable("url", { id: uuid("id") .primaryKey()...
No description

Data types for tables

Currently I receive this type from a db query... Is there a way to have a TS type which encapsulates it, so that I can define a variable of that type more easily?
No description

Neon and Drizzle ORM: Can my schema.ts create my tables in Neon?

As the title suggests, I was wondering if Drizzle ORM can create my tables in Neon from my schema.ts, or if I need to first create my tables in Neon with SQL, and then just create my schema.ts to reflect those tables. Thank you!...

Easiest way to add an array of objects?

Hey, I am trying to add an array of objects to my schema with postgres, how can I do this? there seems to be a pgArray but can't find a pgObject 👀 export const products = pgTable("products", { id: serial("id").primaryKey().unique(),...

drizzle-kit generate:pg - generates incorrect reference to table in another schema?

As im not super comfortable in pgsql, so im unsure if this is intended, or if its a bug with drizzle-kit. Im trying to create a fk reference to "auth"."users", inside my "public"."profiles" table. But drizzle-kit seems to not generate the script with correct reference to the database schema -, am i missing something?...

Help understanding relations

Hey all, just trying to get my head around relations. In this example we have a one-to-many relationship: ```ts export const users = mysqlTable("users", {...

Where does the onDelete on relation is applying ?

For instance : ```ts const product = pgTable('product', { logistics_id: serial('logistics_id') .references(() => logistics.id, { onDelete: 'cascade' })...

How to handle relations during insert?

Is this correct? Feels like I should be able to do it in one call, but values doesn't accept anything else ```ts const group = await db .insert(groups) .values({ name: inputs.name })...

Unwanted db.execute() behavior; trying to pass in an array instead of a record or its singular

When trying to pass an array (ex. number[], bigint[], string[]) that contains only one element into sql``​, it will be transformed into their non-list type (ex. number, bigint, string respectively). When I put two elements in, it then turns into a Postgres record, which is not what I want. What I expect is that the array stays an array. ...