Drizzle Team

DT

Drizzle Team

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

Join

Return array when parsing a schema with drizzle-valibot

Hello guys, I just started using drizzle-valibot and I'm not able to find in their docs nor yours how to return an array when parsing a schema ```ts // Schema export const facturaciones = mysqlTable('...', {});...

Mysql json field in where clause escaping the field name

can some one help me i am traying to create a eq(sql${schedules.extraFields}->>'user', userId),, to acess a json field but the generated query is invalid its escaping the 'user'

What is the best way to create conditional filters on a query?

I am building an marketplace for rural real estate. I would like to build a filter system with multiple options to filter. What would be the best way to do this with Drizzle? It would be like Airbnb....

Creating zod insert schema from Query with relations

I am using a Query FindFirst, with multiple relations enabled. I can infer the schema from this using Awaited<ReturnType<typeof myQuery['execute']>> but this includes the ID field in the relational objects. How can I create a type that matches the query schema, but minus the IDs in the relations? Bonus question, how can I then use Zod to add this type into a zod schema object?...

`.orderBy` influence `sql` output

With the following code: ```ts const exchanges = await db .select({ ...getTableColumns(stockExchanges),...

Do I have to import table name type for select query?

Doing this simple query: ``` dbDrizzle.select({ id: user.id }).from(user)...

Custom SQL in migrations

TLDR: can I change the SQL in migrations or is that considered bad practice? Alright, I need some advice. I am still pretty new to Drizzle but I like it a lot so far. The challenge is that I want to use it with SingleStore. It should in general be compatible with MySQL (sauce: https://docs.singlestore.com/cloud/developer-resources/connect-with-application-development-tools/connect-with-node-js/). They have some time series functionality of course, but I think that can be solved with the magic sql operator. My main concern is that they have custom indexes and table types. ...

TypeError: Cannot read properties of undefined (reading 'type') on drizzle kit push command

Can't run drizzle push:mysql on planetscale database, I'm getting this weird error: ``` + Auditors table will be created + Integrators table will be created...

Bypass migrations when updating Planetscale schema on dev branches

Hi there, Sorry, I'm a beginner in MySQL and databases, but I was wondering if there was a way to push a new schema to Planetscale using drizzle-kit without dealing with migrations. When developing a new feature, many changes might be made to the schema. As such, being able to directly override the schema on my Planetscale's dev branch would be useful!...

Index not being created in table

Hi! I'm using drizzle-kit push:pg to update my local dev database. When I use this command, indices with shared names (e.g. updated_at_idx) only get created on the first table in the schema.ts. For example, if I have: ``` ...

Documentation Nav menu broken on mobile

I cant see the sub menus to navigate around the docs on mobile
No description

Implicit many-to-many schema

I would like to define many many-to-many relations with a more terse syntax. I have a database with many many-to-many relations (~30). They are very basic in the sense that the join tables only contain 2 columns - the ids from left and right. Coming from prisma, I could make implicit many-to-many tables with 2 lines of code (and it would generate 2 more lines automatically)....

Migration Confirmation/Help with PlanetScale

I know I can test this myself but I want to reduce the connections to my PlanetScale database. So, I have my main branch which has a password to it, and a development branch off of the main branch with it's own password. If I use the dev url in the migration config file and main url for the drizzle connection will this cause any issues. Here is what I have done:...

Infering custom types

I am following the guide https://orm.drizzle.team/docs/custom-types#examples referenced here to create a custom JSONb schema. However, when i create an insert schema, the customtype field is of zod any

Why is 1 and 0 are returned as string?

With the following:
isUsed: sql<boolean>`case when ${usedExchanges.data} is not null then 1 else 0 end`
isUsed: sql<boolean>`case when ${usedExchanges.data} is not null then 1 else 0 end`
I get isUsed as "1" or "0" whereas I would expect a boolean....

Custom error messages with drizzle-zod?

Hey there! 👋 Does somebody know how to add custom error messages to a schema created via createInsertSchema? I know I can refine the schema by passing an object as the second argument, but since the error messages are part of the actual type definition, I would be repeating myself like so: ``` export const users = sqliteTable("users", { id: integer("id").primaryKey().notNull()...

how to encapsulate a general pagination function

I am looking to create a generalized pagination function to simplify the implementation of APIs with pagination capabilities. Here's the code I'm currently using: ```ts // api route const routes = {...

Push with schema in separate files

I have my schemas setup something like customer.ts vendor.ts inventory.ts public.ts In my config I have schema: "./app/lib/data/db/schema/*" In public.ts I am creating tables with pgTable but in the non public ts files I am creating a schema with export const customer = pgSchema("customer") and then creating tables with export const customerTable = customer.table("customer", {fieilds here}) When I run drizzle-kit push:pg all that is created is anything in the public file and pgTable ...

Checking Joined Data Directly from Type Recommendation and Retrieved Data in Dynamic findMany

When implementing a join using with in findMany, I wrote the following code to dynamically change the object to be set in with. ```typescript // normal const result = await dbToUse.query.user.findMany({...

SQL noob trying to make schema Drizzle ORM

My confusion comes from how to structure the database so that I don't save duplicate data and when I update I don't leave the data (like promoting agent to lead) I have watched a lot of tutorials but I just can't seem to get the mental model on how to do this or even what would be the best way to do this. where when a user logs in he is assigned a role...