Drizzle Team

DT

Drizzle Team

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

Join

Unique key in PG

Hey guys, sorry I have a little dumb question here 🙂 I wanna know how to set my id field in my PG to auto increament. Here's my schema;...

monorepo migration folder bundling

I have a turborepo monorepo. Trying to have db as a separate internal package along with its migrations folder but the migrate function uses the migrations folder from the client app rather than the package itself ```ts export const initialMigration = () =>...

How to type connection as conn or transaction?

My attempt was like below:
export type DBConn = PgTransaction<NodePgQueryResultHKT, Record<string, never>, ExtractTablesWithRelations<Record<string, never>>> | NodePgDatabase<Record<string, never>>
export type DBConn = PgTransaction<NodePgQueryResultHKT, Record<string, never>, ExtractTablesWithRelations<Record<string, never>>> | NodePgDatabase<Record<string, never>>
but passing transaction to function using it raise error. Any idea?...

Does 'query' support subqueries with filters?

Is it possible to define subquery with filters for many to one relation?

SQLite Timestamp does not allow a default NULL value

As the title says, ```ts updatedAt: integer("updated_at", { mode: "timestamp" }) .default(null)...

Error: "Missing VercelPostgres connection string" when using insert query

Hey gamers, I'm going thru Theo's T3 stack tutorial to build a similar website (but with basic text post CRUD functions instead of images) But i run into problems trying to set up the insert query. I've tried a shuffling things around but i always come to the same error when i run this on dev:
VercelPostgresError: VercelPostgresError - 'missing_connection_string': You did not supply a 'connectionString' and no 'POSTGRES_URL' env var was found....

applying migrations...error: unsafe use of new value "zewnetrzny"

adding model with enum like below (sorry for polish, ubiquitous language with domain masters) ``` export const typUzytkownikaEnum = pgEnum('typ_uzytkownika', ['zewnetrzny', 'wewnetrzny'] );...

Typesafe where? argument possible?

I have a service class containing: ``` async findAll(limit: number, offset: number): Promise<Circuit[]> { logger.debug('CircuitService.findAll() called with limit=%s, offset=%s', limit, offset);...

No config path provided, using default 'drizzle.config.ts'

I’m trying to add drizzle to my Nextjs project. One error says something about es5, so I changed it to es6, Now it’s saying: ...

Define shared columns

hello , please i'm trying to create some shared columns definition in able to be used in multiple tables . my file structure : -> database/tables/<table_name>.ts : containing table definition + relations + schemas + types -> database/tables/utils.ts: containing the shared functions + columns definitions...

drizzle-studio showing duplicate relations

why is this drizzle studio showing duplicate columns for a relationship? Here's my schema file...
No description

confused with relations

Hey guys, I have started working with drizzle relations and finding it a bit confusing compared to prisma relations. My question is, is there any working example available out there with drizzle relations covering all the 1-1, 1-n, n-n, n-1 relations?? I'm using postgresjs for local dev and vercel postgres for prod' Thank you...

Drizzle: recreate tables with different prefix, without deleting the old ones

TLDR; Recreate tables for instances of same appllication (on the same database) I have an application which I'll deploy a unique instance of for each client, I'm using neon for storing data Neon's free plan allows 1 database and unlimited table what I'm doing right now is: ```ts...
No description

how to set pragma foreign_keys = off, during migrations?

Sqlite does not have the best support when it comes to altering columns and I need to manually write them in the generated migration .SQL files. But I keep getting the foreign key constraint error when I try to run the migration even with pragma foreign keys set to off. Thanks in advance.

How to narrow type in select from enum?

During select I need to narrow enum type from multiple choices to one choice eg just 'product' schema ``` export const typAsortymentuEnum = pgEnum('typ_asortymentu', ['produkt', 'usluga']);...

Generic Drizzle ActiveRecord pattern (kind of)

Hi, I'm trying to do a Drizzle model to inherit from it with some generic methods. Maybe is not the right idea but anyway is fun to try it. This is my current implementation: ```javascript import db from '$/db/client'...

One-to-many relation always returning no records for the `many` relation

Hello, I need some help debugging a relation that I have set up for a postgres database. The schema is as follows: ``ts // snowflakePk() is a shortcut for generating a snowflake as the primary key with the name id` export const flows = pgTable("Flow", { id: snowflakePk(),...

Are requests memoized in Nextjs 14?

Are Drizzle requests memoized like fetch requests in Nextjs 14? In other words, can you call the same query in all components that need it without making a ton of requests for the same data?

ERROR [unhandledRejection] connect ECONNREFUSED 127.0.0.1:60589

I use a drizzle-http-sqlite proxy to connect to my remote D1. After a while it hungs with this error. My issue is that I'm not connecting to a localhost so I have no idea why it happens. This is my proxy: ```js import { drizzle as drizzleProxy } from 'drizzle-orm/sqlite-proxy'; ...