Drizzle Team


Drizzle Team

Join the community to ask questions about Drizzle Team and get answers from other members.

Join Server

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
EDEvan Deam11/27/2023

'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:
WHERE p.ID IN (SELECT post_ID FROM ANOTHER_TABLE WHERE post_category = 'whatever')
WHERE p.ID IN (SELECT post_ID FROM ANOTHER_TABLE WHERE post_category = 'whatever')

server does not allow insecure connections, client must use SSL/TLS

I have been trying to setup planetscale database with drizzle in my next js application. But I cant seem to form a conneciton with the database and push my generated schema up. When I run the command npx drizzle-kit push:mysql I get this error ...

Proxy driver result is `undefined` when using a schema

I've created a simple proxy driver with sqlite. The drizzle result is fetched correctly from the database. However, when it's passed through the schema table, the object comes back as undefined for all attributes. Could someone steer me to the right direction on how to address this?...
No description

Getting types for update query

Similar to $inferInsert, is there a $inferUpdate to get types while performing a db.update()

Steps to fix errors like `drizzle/meta/0000_snapshot.json data is malformed`

I am not sure how I got into this state but it blocking any updates to my schema i made issue https://github.com/drizzle-team/drizzle-orm/issues/1554...
No description

Drizzle Studio: Failed to fetch tables from database

Hello! I am struggling to connect to Drizzle Studio with my local postgres database: Failed to fetch tables from database TypeError: Cannot convert undefined or null to object ...