Drizzle Team

DT

Drizzle Team

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

Join

Running local database with edge runtime on NextJS

Hi, I've been trying to run drizzle on /pages/api route (edge runtime) in NextJS but I can't get it to work locally. It feels like I've tried every combination of drivers so far but they either refuse to connect (neon and vercel/postgres for example does not like my connection string), complain about node modules or just doesn't seem to be able to fetch anything (seemingly connects but awaited queries do no not return). I have a postgres database that works with the node-postgres driver for trpc endpoints. Any help is appreciated...
No description

help with a generic mysql2 connection

gday folks, im trying to create what is essentially a generic mysql2 connection that is compatible with planetscale but also compatible with a local msyql2 server running in docker, for instance...my production database is planetscale hosted and any sort of dev or testing i want to do locally. My connection at the moment is literally just drizzle(connection, { mode: DB_MODE, schema }) however due to the sheer amount of options within the configuration im concerned im missing something crucial for the continued integration with planetscale with such a minimal config. granted the port, user, password, schema, etc are all in the uri, but is there anything else i should be considering?...

Select as db column names instead of js property names

Is there a helper to make select queries that return db column names, i.e. snake-cased instead of the camelCased schema names? I figure I can implement pretty easily, just wanted to know if there's already something provided by drizzle?

Unable to make migrations

Hey guys. I don't want to push it too hard, but am I the only one who stuck with this issue? I can not downgrade drizzle kit (it throws error that package is outdated), and I basically can not apply any changes to database - it basically blocked any further development. Do you know any workaround for that, or at least the reason why It's happening? I'm referring to https://github.com/drizzle-team/drizzle-orm/issues/1119...

where(gt) with timestamp returns wrong result

Might be a SQL inherent thing, but I'm a bit puzzled as to why this happens: Edit: for terseness I left out some code. I think the issue is clear ```ts...

node-postgres uses crypto under the hood ?

Hello everyone, so I'm migrating from Prisma to Drizzle so I can use the NextJS's edge runtime I'm trying to make a query inside my edge middleware and I get the following error: The edge runtime does not support Node.js 'crypto' module. ...

SyntaxError: Unexpected identifier 'SCHEMA'

I'm trying to execute "drizzle-kit generate:pg" and I'm receiving error: CREATE SCHEMA "boards"; ^^^^^^ SyntaxError: Unexpected identifier 'SCHEMA'...
No description

How can I create a virtual table with sqlite?

I am using turso & sqlite. I have enabled the FTS5 extension so I can perform full text search. I want to define a virtual table in my schema so I can query it using drizzle. If I define it as a regular sqliteTable, running db:push from drizzle kit will create the table and break the virtual table. What's the best way to proceed?

Is it possible to identify modifications in a pg db and extract/pull them as a new migration file?

Here is the situation I am referring to: 1. When I run drizzle-kit introspect:pg for the first time, it generates 0000 migration. 2. A new table called my_new_table is created using native pg (without ORM). 3. (I wish to) When I run drizzle-kit introspect:pg for the second time, it generates a 0001 migration with my_new_table included....

PostgreSQL "type serial does not exist"

I'm getting an error when using serial and primary key. Just trying out postgres for the first time so its very possible I messed something up, the serial type works perfect on non primary key fields ```ts export const users = pgTable( "users",...

how to express the "children" relation in parent/child?

I have a table with columns id and parent_id - and I want to setup a parent/child relationship. Using the relations, one, and many I've got this but not sure if it's correct. If I'm able to express my "parent" relationship, shouldn't I also express my "children" relationship as well?...
No description

Too many clients already (!?)

Hey guys, been using Drizzle for a few weeks now and I think since last week this issue has started (look at screenshot). I'm using the postgrespaackge to connect Drizzle to my PostgreSQL database that's deployed to Railway. Drizzle connection code 👇 : ```typescript...
No description

Help, issue that will drop our user table

We generated and pushed our schemas to a dev branch in planetscale, and then deployed that branch no issue. One of the schemas was the User schema. We added two schemas to our db and pushed to dev again, no changes were made to the User schema, yet pushing to the dev db wants to truncate our user table because of the createdAt and updatedAt columns. What is happening and what should we do? Schema ``` export const user = mysqlTable(...

How to use a composite primary key in WHERE?

I have a table dv360UserProfilesTable which uses a composite key of userId and assignedUserProfileId. If I want to update this table, I'm struggling with how to use the composite key to batch update profiles. The below code throws the error: db error: ERROR: argument of WHERE must be type boolean, not type record The docs also do not show an example of this https://orm.drizzle.team/docs/indexes-constraints#composite-primary-key ```...

Having statement to compare sql<number> and number

Sorry if a dumb question, I'm working on an aggregation query like: ``` const query = await db .select({ workerUid: workerStatsDaily.workerUid,...

Select EXISTS

How to query boolean value if row exists or not. In pure sql it will be like this:
SELECT EXISTS(SELECT 1 FROM your_table_name WHERE id = 1 AND version = 5)
SELECT EXISTS(SELECT 1 FROM your_table_name WHERE id = 1 AND version = 5)
...

Zod schema validation from Drizzle schema

Hello i have an issue with zod creating schema from drizzle. I don't understand why my categories won't works while my customers works with the same export code feel free to ask more elements I know that it could be a zod issue but there is no one active on their server and maybe someone here can help since i had recommandation tu use zod in this discord server...

Each element of array is a foreign key

Hello, I'm trying to figure out how to create a postgres schema that will hold an array of ids property, and each element of that array is a foreign key. Is this possible with Drizzle? Here's my implementation: ```typescript...

Buffer isn't defined

I use blob mode:json for my fields and run it on Cloudflare Workers. But I get that Buffers isn't defined. As I understand blob only compatible with Node.

Is it possible to do lateral sub-query join without relational queries?

I'm trying to rewrite the same query that the relation query builder does behind the scenes but not sure if it's possible If i log the query this is what i get ```sql select "articles"."id", "articles"."title", "articles_keywords"."data" as "keywords" from "articles" left join lateral (select coalesce(json_agg(json_build_array("articles_keywords"."article_id", "articles_keywords"."keyword_value")), '[]'::json) ...