Drizzle Team

DT

Drizzle Team

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

Join

Many to many flatten response

I'm struggling to understand why does drizzle work this way and why there isnt an easy way to flatten the response structure. I have 3 tables, Profile, Interest and Language. I also have 2 other join tables, ProfileInterest and ProfileLanguage. As you may have noticed, I have a many-to-many relationship between Profile and Interest and between Profile and Language. All 5 tables are in place (3 "models" and 2 join tables). I also have all the relations created and everything works as expected. To query for a specific profile including its' interests and languages I run the following. ``` db.query.Profile.findFirst({ where: eq(Profile.id, input.id),...

Cloudflare D1 using drizzle - issue with boolean data type

Even if the SQlite column is typed as boolean, I am getting an integer value and having to explicitly cast it to boolean
No description

ERROR WHILE INSTALLING DRIZZLE-ORM

``` $ npm i drizzle-orm npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR!...

duplicate key value violates unique constraint when trying to insert

I have this simple table: ```javascript export const ExperimentData = pgTable('experiment_data', { id: bigserial('id', { mode: 'number' }).primaryKey(), timestamp: bigint('timestamp', { mode: 'number' }),...

PostgresError: sorry, too many clients already

```js import { drizzle } from 'drizzle-orm/postgres-js'; import { migrate } from 'drizzle-orm/postgres-js/migrator'; import postgres from 'postgres'; import * as schema from './schema';...

Unable to run migration pgenum

``` import { pgTable, serial, text, varchar, pgEnum, numeric } from 'drizzle-orm/pg-core'; const roleEnum = pgEnum('role', ['admin', 'user']); export const users = pgTable('users', {...

drizzle-kit can't connect to Vercel postgres instance

I am following theo's From 0 to production - The Modern React Tutorial but I am unable to use drizzle-kit to connect to the postgres instance. I just get ETIMEDOUT whenever I try any of the drizzle-kit commands. (See attached error). I can connect using psql and telnet just fine.

drizzle-kit generate not working with unhelpful error message

Ian into an issue with generate yesterday and can't really make sense of the error... ``` drizzle-kit: v0.22.7 drizzle-orm: v0.31.2...

Issues with foreign keys and entering null values

I have 2 schemas: export const items = createTable( "items", { id: bigserial("id", { mode: 'bigint' }).primaryKey(),...

How should I do custom migrations?

I am trying to do migrations in sqlite and sometimes drizzle will leave a comment in the migration file saying it cannot add constraints to existing columns, I understand it is necessary but it'd be appreciated if there was better documentation on how to achieve these things without leaving drizzle too much. I feel like the whole migration process from drizzle-kit is not that clear and its quite hard to understand what are its limitations. For instance, I had a 0005_etc migration file written by me (I guess this is necessary to keep it version-controllable) and it used BEGIN TRANSACTION; Now, trying to run my 0006_etc file I am getting SQL_MANY_STATEMENTS and if I add statement-breakpoints I get SQLite error: cannot start a transaction within a transaction I am unsure about whether it has to do with this file or the previous one. Some of the questions that I am now getting: - Does running drizzle-kit migrate run all files? how does it decide which to run? - Why can't it point me to the file/statement that is erroring?...

Switching between single and composite primary keys

I have resolved this by nuking my database and all migrations then recreating, but I ran into this error when changing the nature of primary keys. It also wouldn't let me remove the table by way of migration.
TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys')
at .../node_modules/drizzle-kit/bin.cjs:27627:67
TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys')
at .../node_modules/drizzle-kit/bin.cjs:27627:67
...

fetching migrations

(Nextjs, turso, drizzle. 1 db per tenant, created on onboarding) I get an error message today from a drizzle batch operation that I can't find any info on. "Unexpected status code while fetching migration jobs: 400" ...

studio

Pls help studio keeps on loading
No description

Correct way to instantiate a different client per environment?

I have a sst project which I also would like to run locally with a local postgresql connection and without instantiating a new AWS stack for it. This is my current approach, but I don't think it's great since the type of db ends up being polymorphic. ``` import { drizzle as pgDrizzle } from 'drizzle-orm/postgres-js'; import { drizzle as awsDrizzle } from 'drizzle-orm/aws-data-api/pg';...

Conflicting peer dependency of react@18.2.0 when installing drizzle-orm@0.31.2 in Next.js 14.2.4

Hi I'm install drizzle-orm in a Next.js project initialized with create-next-app@14.2.4. This new project has dependency to React 18.3.1....

How can I append a subquery as an array in the main query select?

How can I append a subquery as an array in the main query select? I'm currently using the alternative which is to use relational queries, but when using the db.select() syntax, is it possible to append subqueries or any leftJoins for that matter as an array in the final select? ```typescript const subquery = db .select({...

SQLITE error "Table already exists"

Hello, I've run drizzle-kit up and drizzle-kit generate, but when I run migrate I get an error saying that a table name already exists. (Error, below) My understanding is that this would just alter one of my tables based on my schemas, am I misunderstanding something? applying migrations...LibsqlError: SQLITE_ERROR: table table_name already exists...

Drizzle Zod with relations

Is there any easy way to get Drizzle-zod to include relations on select schemas? I was able to come up with using zod's extend method to manually chain together a new validator, but an automatic solution would be pretty nice.

Automating migration

I am considering adding code to run a migration within my server startup. Basically, any time the server starts, the migration will run. The idea is that when the code is updated and the server restarts, the database stays up to date. My questions: a) is there a way programmatically to determine if there is a need to do a migration? b) is there are a harm in running the migration every time you start up your server (migrate(database, { migrationsFolder: './db/drizzle' });)...