Drizzle Team

DT

Drizzle Team

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

Join

Is it possible to introspect relations?

Let's say I have the following relation def: ```js export const externalUsersRelations = relations(external_users, ({one}) => ({ users: one(users, { fields: [external_users.user_id],...

Polymorphic relationships using a discriminator column

Hi all, I'm currently migrating (tbh rebuilding) a project that currently uses Entity Framework. In the database, we currently have a few polymorphic relationships, represented with a discriminator column. E.g. LicenseAssignments has a column LicenseTargetDiscriminator (which could be something like User, Organisation, Document, etc.) and a column LicenseTargetId which contains the ID of the resource in its particular table....

JsonB and $type

I don't get how we're supposed to use jsonb types with drizzle-orm and drizzle-zod if we use jsonb().$type<SomeType> then it seems that when we use createInsertSchema etc we still need to add a refinement for the field or we have type issues I created some issues on the repo to have more infos, but perhaps someone here knows what are the best way to handle typed jsonb fields? issues: https://github.com/drizzle-team/drizzle-orm/issues/4361 and https://github.com/drizzle-team/drizzle-orm/issues/4366...

Drizzle push not respecting .existing views. Have to drop the view everytime i change schema

Like the title says, everytime i change my schema and push it via npx drizzle-kit push. It prompts me to drop the view table. ```ts...

How to make a wrapper function for a table (after version 0.39.0)?

Prior tot 0.39.0 I could easily make a wrapper function for a table, but since 0.39 the typing broke and gives multiple typing errors (even though the code does run properly). See discussion here: https://github.com/drizzle-team/drizzle-orm/issues/4069#issuecomment-2692199268 But for who doesn't like to click through: Same issue for all my table wrapper functions:...

Cannot be cast automatically

I've been struggling with this error for hours. error: column "status" cannot be cast automatically to type service_status also had an issue with enums. I've tried dropping the table and building brand new, still same issue when I run a DB push. Anyone have any insights or ideas?...

how to set an initial autoincrement value

Hello, I want to set an initial autoincrement value for a table. which can normally be achieved with something like: ALTER TABLE penguins AUTO_INCREMENT=1001; how can I achieve this on schema generation?...

Complex filter on query.

Hello everyone, here's the query : ``` db.query.ordersTable.findMany({ with: {...

Magic sql does not add table name in query?

Here's the sample: ``ts const userSubQuery = sql<{ logo: string | null; email: string }> (...

Package pg can't be external

I am creating a turborepo with two next.js apps, and a db package that uses drizzle-orm, and api package that uses trpc. I have things set up according to the docs, but when I run the web app (pnpm run dev), it error out with the following error: ```shell...
Solution:
Solved it by add hoisting the pg package in .npmrc file public-hoist-pattern[]=*pg*...

Problems querying with findMany and relations

Hi. I started trying out drizzle (0.41.0) today and sql-like queries work pretty well. Unfortunately I have a problem with the findMany query when including relations. I created a schema "studentsTable" and set a simple one-to-many relation at "dormId" to the schema "dormsTable". When querying with findMany() and trying to get the relation I always get ⨯ TypeError: Cannot read properties of undefined (reading 'referencedTable') ```export const studentsTable = pgTable("students", {...

Generating/ applying migrations directly in code instead of using the CLI?

Hey! I use drizzle in both my frontend and backend via sqlite and postgres modules, one thing I've found annoying is that I have to generate migration files for tests, even thought I would just prefer to be able to infer the create table statements from the schemas themselves. Is this possible now?

Generated many Relations not available in Relational query builder.

Just a quick sanity question before the end of my workday. I have this relations generated from migrations: picture 1 But they do not seem to be shown in the query builder: picture 2 & picture 3 I am using "drizzle-kit": "0.24.2" ATM, because of a few personalized patches in the package (like the schema naming convention), if this is something version related, will try to upgrade....
No description

Magic sql'' operator concat

I'm getting a strange error when I try to use concat with the sql operator. I'm getting error: column " " does not exist when running this query: ``` const result = await db.query.user.findMany({ columns: { id: true,...

Error in `migrate` command: `PostgresError: no schema has been selected to create in`

``` bunx drizzle-kit migrate No config path provided, using default 'drizzle.config.ts' Reading config file '/Users/ftzi/dev/main-nextstack-website/drizzle.config.ts' postgresql://neondb_owner:DkIm2cK9NiCe@ep-raspy-math-a2mlj10n-pooler.eu-central-1.aws.neon.tech/neondb?sslmode=require...

Need help with relation

I have two tables: characters and character_scores. They are linked by an id column. characters can have many of the same ID and character_scores as well. I want to make a relation between those ID's so that when I query a unique row from characters I want to include the associated character_scores row(s). So for example (pseudo sql):
from characters I want 1 row where id = x and specialization = y and include columns from character_scores where id = x and category = z
from characters I want 1 row where id = x and specialization = y and include columns from character_scores where id = x and category = z
...

Buffer is not defined - drizzle-arktype

I got this error when importing a file that hasimport { createInsertSchema, createSelectSchema } from 'drizzle-arktype' into my vite app
No description

Running multiple projects from one database

I'm pretty new to backend concepts and drizzle. I have created one project already using T3 stack + drizzle and have the database on Supabase. It's deployed and working as expected but I am now looking at starting another project. I am aware that the following bit of table creation code effectively allows me to run multiple projects on one database as all tables for that project are prefixed:...

GraphQL deeply nested relations

I see https://github.com/drizzle-team/drizzle-graphql/releases/tag/0.7.0 has a depth limit of 2 (and 2nd does not have relations). Is there anyway to make the second have relations / have depth limit of 3 maybe......

Seed local SQLite database from Remote D1 data?

Hi Drizzle team, I've been doing some basic testing of D1 with Drizzle and I've added some data to my remote D1 instance with Drizzle Studio. I see that the updated data is in my remote D1. However, when I migrate and run wrangler dev, I don't see my data in local. What am I missing?