Drizzle Team

DT

Drizzle Team

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

Join

[Solved] drizzle-seed autocomplete not working if there are enums or zod objects

Not sure which tag to use for drizzle-seed . I'm trying to seed my database and I was surprised that I wouldn't get table autocomplete inside the seed function when the schema is in different files. Whenever I import * from "./single-file" everything seems to work. Curiously when I deconstruct the import for a specific table, I lose the autocompelte. The tsconfig is in the comment below. Case 1 (works) - import * as schema from "./schema/contexts"...

utility function for COALESCE

I have a CTE and I want an array to coalesce to [] and the count to coalesce to 0. ``` export function aggregateAsArray<Column extends AnyColumn>(column: Column) { return sql<...

🚨 Issue: Testing with PostgreSQL and Drizzle ORM using Testcontainers

I’m writing tests for a function (listProjects) that interacts with a PostgreSQL database using Drizzle ORM. The problem is that listProjects is using a global db instance, which is initialized in the main application. In my tests, I want to use a PostgreSQL container from Testcontainers to spin up a test database, but my test code ends up using a different db instance, not the one I need. ```ts import { drizzle } from "drizzle-orm/postgres-js"; import postgres from "postgres";...

Enum in Unique Constraint throws error.

Environment: drizzle-orm "0.36.0" I have one file that has an enum:
export const myEnum = pgEnum('myEnum', ['A', 'B', 'C']);
export const myEnum = pgEnum('myEnum', ['A', 'B', 'C']);
...

define where query outside

I dont understand why this code works : `` const whereQuery = exists( db .select({ id: sql1` })...

Read replica + schema

Hello! I want to start using read replicas: https://orm.drizzle.team/docs/read-replicas Current I'm doing...

drizzle-zod 0.6.1 has errors on each createXyzSchema

Hey everyone, Does anyone know how to handle this error:
The inferred type of 'selectWorkspacesSchema' cannot be named without a reference to '../node_modules/drizzle-zod/schema.types.internal.mjs'. This is likely not portable. A type annotation is necessary. ts(2742)
The inferred type of 'selectWorkspacesSchema' cannot be named without a reference to '../node_modules/drizzle-zod/schema.types.internal.mjs'. This is likely not portable. A type annotation is necessary. ts(2742)
...

conditional columns

is there a better way of doing this? if the userType column equals to 'artist', the nickname column should be notNull(), but in case of 'customer' it should be null also, the firstName, lastName and the city columns should be filled out before isSetupComplete column can be set to true below is what i came up with open to tips and suggestions, thanks in advance!...

Drizzle-Zod extend schema....

My extend schema no longer works "drizzle-orm": "^0.38.3", "drizzle-zod": "^0.6.1", "drizzle-kit": "^0.30.1",...
No description

drizzle-kit commands are slow

I am not sure if this problem is only in my windows PC. When I run drizzle-kit commands like generate and migrate, the operation seem to take no time, like in producing the migration file but the command takes quite some time to exit like half a minute or so. Is this related to the commands or the conditions of the pc, like RAM, CPU, running tasks, et cetera?

drizzle-kit push not working with pgSchema

Hello, this is my first time using Drizzle and am running into some problems pushing my schema out. I have the following docker-compose.yaml that is spinning up a Postgres instance alongside Adminer. ``` services: db:...

There is not enough information to infer relation "group.users"

I first time use many-to-many relation and i don't know why this is not work. Please help.

Need help with type issues on InferInsertModel and InferSelectModel

In the screenshot I have attached my user schema and I'm creating types for them using the InferInsertModel and InferSelectModel. But however when I hover the type variables CreateUser and User I'm getting generic types instead of user schema type as you see in the second screenshot. Am I doing anything wrong here?...
No description

Drizzle-kit force rename

Hi, i am getting an confirmation choices which is a problem when i try to automate the migration with docker. is there any way to force rename or other work around?.this is the example of the problem i get with "push" command when i use "migrate" i get error if i already have table with same name as drizzle remove CREATE IF NOT.
No description

Error code 5: database is locked ExpoSQLite

Hi, hope you are well. Hopefully someone can help me as I am going loopy with this one. I recently upgraded to Expo52 and decided to give drizzle a try, all is well with select, but any insert returns: ```[Error: FunctionCallException: Calling the 'getAllSync' function has failed (at ExpoModulesCore/SyncFunctionDefinition.swift:137)...

Struggling to setup postgresql in prod, pglite in dev

i have the following drizzle-dev.config.ts: ```import { defineConfig } from "drizzle-kit"; export default defineConfig({ out: "./drizzle",...

Cannot read properties of undefined (reading 'findMany')

Hello, I have a simple schema and an empty table and I can call my database wiith sqllike query but not with the querybuilder, i dont understand why, am I missing something? ty guys ```js...

Generated Postgres Column adding together other columns that may have null values

This code works until one of the numeric values is null, then the totalQuantity becomes null as well. Is there a way to do this in a drizzle schema that would account for the potential nulls? ```JS const supplyItem = pgTable('supply_item', { id: bigint('id', { mode: 'number' }).primaryKey().generatedAlwaysAsIdentity(),...
Solution:
Want to try something. In the generated always as expression, remove the table name before each column name ("supply_item"."location1_quantity" -> "location1_quantity")

Is there any way to have a subquery in an insert statement?

I want to use drizzle to replicate this sql:
INSERT INTO games (name, sortOrder)
VALUES ('New Game', COALESCE((SELECT MAX(sortOrder) FROM games), 0) + 1);
INSERT INTO games (name, sortOrder)
VALUES ('New Game', COALESCE((SELECT MAX(sortOrder) FROM games), 0) + 1);
...

Need help with InferSelectModel

As you see in the screenshot, I have a booking schema and creating types for them using InferInsertModel. But when I hover over the CreateBooking type it shows only some columns from the booking table and most of the columns are missing. Any idea why it behave like this?
No description