Drizzle Team

DT

Drizzle Team

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

Join

defaultRandom() on uuid results in an error

id: uuid('id').unique().primaryKey().notNull().defaultRandom(),
id: uuid('id').unique().primaryKey().notNull().defaultRandom(),
upon insert, this results in the error: NeonDbError: db error: ERROR: invalid input syntax for type uuid: "ia4afwolcuk4rks"...

Handling self referencing foreign keys

I have the following code but am getting an error that says 'people' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022) How should I handle a self referencing foreign key like in my example below?...

WITH RECURSIVE

Is there a function WITH RECURSIVE yet?

sqlite encode

I'm trying to encode some data in the schema. I thought I could use the sql command, but I think that's only for doing default values Like for this table:...

convert from prisma

how can this relation and model with drizzle ?
No description

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,...