Drizzle Team

DT

Drizzle Team

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

Join

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...

How to check if a row exists in Drizzle?

According to this StackOverflow post: https://stackoverflow.com/questions/7471625/fastest-check-if-row-exists-in-postgresql The most performant way to check if a row exists is as follows: ```ts SELECT EXISTS(SELECT 1 FROM foo WHERE id = 123)...

import of drizzle-orm makes typescript complain about missing "document"

I'm using drizzle with the qwik framework. When import anything from drizzle-orm, typescript complains about document to be unavailable (see attached image). Without the import, everything works as expected. Is there any way to fix this?...
No description

unionAll gives TypeError: leftSelect.getSelectedFields is not a function

I'm trying to query 2 collections in the same query as the amount of collections might grow over time that I will check against I would want a scalable way and also use drizzles built in features, so I tryed this: Note I'm using Payload CMS, so I don't have access to the schema files directly, actually got no clue if its db.schema or db.tables I should use. Running these queries separately works great, just when I add unionAll I get:...

What are the Drizzle conventions for giving names to Drizzle return types?

Hello all, I have a question about Drizzle conventions. Do people give names to the return types of their Drizzle calls? For example, consider the following code: ```ts import { eq } from "drizzle-orm"; import { usersTable } from "../databaseSchema";...

drizzle studio blank screen

the behaviour is same on both firefox and brave(shields disabled), so doesn't seem like a browser problem.
No description

'columns' does not exist in object passed to primaryKey() fn

Bootstrapped a project with CT3A@latest (drizzle-orm v ^0.28.5 in my package.json). I'm trying to create a composite primary key for a table, but the only way I've been able to get the primaryKey() function to work is to simple pass in comma separated table.columns (e.g. primaryKey(table.column1, table.column2, etc.)). I think because of the length of the column names that make up the composite primary key, I'm getting a MySQL error no. 1059 (identifier is too long). I can do primaryKey({ name: "custom_name"}), but I'm not sure how to designate the columns I want to make up the composite key, since the TS engine is telling me 'columns' doesn't exist on this object getting passed into primaryKey(). Are the docs not update with the most recent release? Is there a way to work around this, or should I use a previous release of drizzle-orm? TIA!...

How can I do a join query for the sole purpose of filtering?

Essentially my question is how can I do this better in drizzle. ```js const myTeams = await ctx.db .select()...

type is not registering

I don't understand, I see the type there but it's not registering or am I missing something
No description

Map casing when using sql`` operator

If I query my table using the magic sql operator. How can I get back the column names like userId instad of how they are in the tabel user_id?

Mysql JSON_ARRAYAGG as a string instead of a json

Hi guys, how are you ? I'm trying to use a sub query to get and array of objects but in the result i'm not sure how to get the array and dont' get a string My query is like this ``` const data: PaymentResponse[] = await db...

How do you write a query to get the relations data together with a JOIN or a SUBQUERY?

I need to run something like:
SELECT * FROM POST p
WHERE p.ID IN (SELECT post_ID FROM ANOTHER_TABLE WHERE post_category = 'whatever')
SELECT * FROM POST p
WHERE p.ID IN (SELECT post_ID FROM ANOTHER_TABLE WHERE post_category = 'whatever')
...