Drizzle Team

DT

Drizzle Team

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

Join

How do I type a generic crud service?

I am attempting to create a generic Crud service that has methods to CRUD any table. All my attempts thus far has failed to overcome TS errors. I'm a novice at Drizzle and although proficient by no means an expert at TS. All hep is appreciated. Here is my latest attempt so far along with the TS errors: ```TS import { Context } from "hono"; import { PostgresJsDatabase } from "drizzle-orm/postgres-js"; import { getDatabase } from "../utils/db.utils"; import { PgTable, TableConfig } from "drizzle-orm/pg-core";...

How to access JSON nested value within a `select()`

Having this schema: ```ts type Breakdown = { land: number;...

Fighting with migrations

Hi, I have a SQL database that I should keep. I messed up my migrations. i tried to restart from a blank slate. - Removed the migration (in database, in files (snapshot, migration files and journal file)) - I did a npx drizzle-kit pull...

Smart way to prepare data for frontend

As you can imagine, query returns aren't exacly pretty, and they'll have rows for each value that matches. For example, let's say you want to grab posts and comments. On your select, you'd have a row (or in drizzle case, an object for each row) for each post and comment. something like
[{postId:"1",commentId:"1",text:""},{postId:"1",commentId:"2",text:""}]
[{postId:"1",commentId:"1",text:""},{postId:"1",commentId:"2",text:""}]
...

Inferring schema with drizzle-zod in sveltekit app

I am using drizzle orm in a sveltekit app and the logical place to define my db schema is in the lib/server/db directory. I am also using shadcn with superforms, which require a schema definition for validating the inputs (i am using client side validation as well). The problem is that having the table definitions inside the lib/server folder is preventing me from inferring the schemas for my tables with drizzle-zod and use those in client side code. At the moment I am forced to define a separate schema (basically duplicating information) for insertion. My question would be: has anyone faced this problem, and if so what was you solution? I would be happy to provide more information as needed. Thank you!...

_snapshot.json data is malformed

Whenever I run npx drizzle-kit pull to get my pre-existing Supabase schema it works. If I then try to run npx drizzle-kit generate it says supabase/migrations/meta/20241203225947_snapshot.json data is malformed I don't know what is causing the issue. I did not edit the 20241203225947_snapshot.json...

Guidance on Creating a Multi-Tenant Application with PostgreSQL Schemas

Hi friends, I’m working on creating a multi-tenant application where each tenant is assigned a separate PostgreSQL schema. I have a few questions and would greatly appreciate your insights: What is the best approach to implement this kind of multi-tenancy?...

PgEnum Error on relation

error: column "xxxxxxxxxxxxxxx_name" of relation "xxxxxxxxxxxxxxxx" does not exist I cannot understand why i get this error....
No description

Is this a proper way to type a table and column?

I want to make certain crud action reusable in my codebase. Is this the proper way to type a SQLite table and column? Load activeItem function ```typescript...

Latest drizzle-orm 0.37.0 break drizzle-zod

Everything working fine with 0.36.4, but with latest got type compatibility issue between exported drizzle schema and drizzle-zod createInsert/SelectSchema Type Mismatch: Trying to use a PgTableWithColumns (PostgreSQL-specific table) where a generic Table type is expected. Column Type Incompatibility: The specific issue is with the column types: Used: PgColumn (PostgreSQL-specific column type)...

How to setup vercel/postgres locally

I tried this Local Development with Vercel Postgres, but I can't push schema. Anyone know how to solve it? ---...

Data-loss when pushing changes for geometry

As title mentioned. I'm getting "You're about to change location column type from geometry(Point) to geometry(point) with 8 items" This is my table: export const informationsTable = schema.table(...

cant insert after using drizzle-seed

schema ```ts const usersTable = pgTable('users', { id: integer().primaryKey().generatedAlwaysAsIdentity(), email: varchar({ length: 255 }).notNull().unique(),...

No schema loaded in Drizzle Studio

I'm starting up Drizzle Studio after updating to the latest versions: "drizzle-kit": "0.29.0", "drizzle-orm": "0.37.0". The studio loads in with no schema and I have no idea why. I'm connecting to a Planetscale DB and following the docs to a tee using their driver. My configurations are all correct, and I can confirm my environment variables are making it into the config and everywhere else. I do have this set up in a monorepo, but this only recently started occurring. I even reverted to an older version and the same things happens. - Introspection seems to work just fine...
No description

What's the recommended way to handle joins that aggregate results?

I'm currently converting a codebase that uses raw sql postgres queries over to drizzle, and have this query: ```sql SELECT games.name, games.image_url,...

with clause type not being inferred properly on insert

I have to assert it as a number for the type error to go away: ``` const countryIdQuery = db.$with('country_id').as( db...

How to dynamically select all columns from one table, and join a single column from another table?

Its pretty often that I need to grab some details from a relational table and add it in to my original query. However, when I do this, I then need to explicitly call out all columns on the original table, and compose in my values from the join table. This can become tedious when I have many columns or when a column is added on the original table. I was hoping I might be able to spread out my reference to the PgTable and just add in one other key for the other table, but this isn't a valid query. Wrong ```typescript const existingReport = await db...

Does local.drizzle.studio/index.js weight 18 megabytes for real?

Hello! I am not sure if my internet speed is so slow or your build is broken, but did https://local.drizzle.studio/index.js always weight 18 megabytes? It takes ages to load drizzle studio in web browser. When it loads, it works....

Next.js, Drizzle and Supabase DB with transactions?

Hey, I really appreciate the value of transactions. They grant safety when handling multiple changes at once. I am setting up my Next.js project. I want to use Drizzle to handle my tables in my code....