Drizzle Team


Drizzle Team

Join the community to ask questions about Drizzle Team and get answers from other members.

Join Server

Connection hangs in AWS Lambda when using response streaming

I know that this issue is not really drizzle related but there might be someone who can help me out I have a lambda function that I want to use to stream responses. If I create a DB connection to make some queries within the lambda, after the streaming ends, the lambda just hangs and eventually times out. I assume that it has to do with the fact that there is an open db connection, which I don't want to close because then I can not reuse the same db connection for following invocations. ...
No description

nullsNotDistinct on composite unique

I have the following table ``` export const customersTable = pgTable("customers", { id: serial('id').primaryKey(), first_name: text('first_name'),...

Sqlite syntax error when calling useMigrations in react-native expo app

Hello, I'm currently trying to set up a React Native app and having some problems with useMigrations. The error is complaining about the syntax but it looks fine to me: ```ts error: SyntaxError: /root/coding/kutuba-app/drizzle/0000_stale_natasha_romanoff.sql: Missing semicolon. (1:6)...
IYIlan Yehezkely4/12/2024

Is this the correct way to use With clause (CTEs) to delete a row using only one transaction?

`export const deleteMainAccountUser = async (publicUserId: string, publicMainAccountId: string) => { const userId = neonClient .$with('user_id') .as(neonClient.select({ id: user.id }).from(user).where(eq(user.publicUserId, publicUserId))) ...

Parameterized Interval in Where Clause

I'm trying to write a query that uses an interval as a parameter. The SQL looks like this and works fine:
where now() - interval '1 month' < table.date
where now() - interval '1 month' < table.date
When I try to write it using drizzle, it also works fine if a hard code the interval:...


if i try onConflictDoNothing the plan is to insert a new record into the database. If a record with the same userId and provider already exists, and the apiKey of the existing record is not equal to the apiKey of the new record, the insert operation is skipped and no error is thrown. `` .onConflictDoNothing({ target: [userId, newSettingInfo.provider], where: sql${settingInfo.apiKey} != ${newSettingInfo.apiKey}`,...
CHChi Hao4/11/2024

update multiple rows is not working. PostgresError: column excluded.name does not exist

I'm trying to insert multiple rows and update onconflict for those rows that have conflict. ```ts export type OrderPhases = { restaurant_id: number; uuid?: string;...

How to reference composite key in foreign key

I'm trying to create a foreign key which points to another tables composite primary key. I cannot seem to find anywhere how this is meant to be achieved. I have attached a simplified version of the code I am trying to get to work. As you can see in the moves table I am creating a composite primary key. How do I then reference that in the moveTimestamps table. Also, what should I put in place of varchar in the moveTimestamps table move column, typically I would just match the data type as what it is referencing, but in thise case it should reference both an interger and a varchar. ```typescript...

Generating migrations after pull tries to recreate existing FK constraints with different name

Hi there! I'm starting to implement Drizzle at work. I introspected our database and generate table models without a problem. After that, to test out migrations, I deleted some columns and decided to create my first migration. ...

How to call a method based on a condition?

I am running two almost similar queries based on a condition. In one of the condition I'm calling the where method and in the other one I'm not. How can I reduce duplicacy by having just one query that works for both conditions? Basically calling the where method only if a condition holds. ```ts if (id === -1) chunk = await db .select({...

Drizzle-Studio does not connect

Successfully pushed test data to neon. When I run "db:studio": "sudo npx drizzle-kit studio", I get the following: Connecting to the Drizzle Kit on localhost:4983 I've rebuilt and went through tutorials, cannot find a reason the studio will not connect....

How to migrate this betterSqlite3 query to drizzle

```export const search = async ( text: string, { filterId }: { filterId?: string } = {}, ) => { if (!text) return [];...

Huge Performance difference between select and query

I was wondering if there should really be a more than 250x performance difference between the same query using select with leftJoin and query ``` const rows = await db .select() .from(transactions)...

Error using "with" in nextjs

Hey, I'm using mysql and next.js and I'm migrating from Prisma to Drizzle. I don't know why, but when I try getting items using "with", it says: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(select coalesce(json_arrayagg(json_array(category_items.id, category_it...'at line 1. WIthout the "with" it works fine. My query: `await db.query.category.findMany({ with: {...
JKJackson Kasi4/10/2024

Issue Querying Table via Drizzle ORM with SQLite

Hello Drizzle Community, I'm currently facing an issue with querying the tbl_workshops table in a SQLite database using Drizzle ORM. Despite confirming that the table exists and is properly structured (I can query it directly using SQLite tools), attempts to query it through Drizzle result in an error indicating that the table doesn't exist. Error Message:...
No description

introspecting database different foreign key names when creating migration.

Hello, I'm migrating a database without an ORM to using drizzle. I've introspected my database and created my first migration, however when I create the migration it renames all of our foreign keys....

MySQL with Unix socket connection

does drizzleORM offer support for Unix Socket connections, i cannot find anything in the documents that explicitly state that it is supported. This is in specific regards to MySQL2

How to tell Drizzle that a column whose value is assigned in a pg trigger is not required

I have a non-nullable column whose value is set in a Postgres insert trigger (like NEW.count = 123). How can I avoid TS errors when I try db.insert(myTable).values({})? Drizzle is complaining that count in this case needs a value.

Issues with the "with" parameter

Hello! I am super sure this is a noob questions but this is my first time using Drizzle with Hono in Bun, coming from sequelize. So I am trying to make this short: When I try to do ```ts apps .get('/:identifier', async (c) => {...
No description
LGLuke (Glazy)4/9/2024

Transaction-based testing

I'm keen on setting up ActiveRecord-like transaction testing with Drizzle. For the uninitiated, this involves setting up and then rolling back a database transaction for each test. Has anyone got an example of this working with Drizzle and/or is this currently possible? I know ActiveRecord in particular has some logic internally to handle the rolling back of potential nested transactions....