Drizzle Team

DT

Drizzle Team

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

Join

How do you define two tables that have foreign keys to each other? drizzle-kit introspect fails

Drizzle-kit now generates a schema file with type errors - it was previously working prior to 0.24.0. In addition, the generated foreign key entry for multicolumn foreign keys has the columns in the incorrect order. (code below due to length limit)...

Neon can use client component, but not local postgres? - next14,postgres,drizzle -

Hi, how to re-create this use-effect using a server component? useEffect(() => {...

Using MSSQL Server

drizzle-team/drizzle-orm has a branch for MSSQL, however there doesn't appear to be a way to install it. Is there any way of doing this, accepting that I will deal with any bugs that may exist in a development branch?

In a relation subquery, how to reference parent column?

I have this query: ``` const result = await db.query.author.findFirst({ where: (author) => eq(author.slug, params.slug),...

example for drizzle + SQLite + next.js + migrate -> docker

Has anyone seen an example for drizzle + SQLite + next.js + migrate -> docker?

Using function in "and" instead of dynamic query

Hey i was wondering if this would work or if there would be any downsides ```typescript await db.query.myTable.findFirst({ where: and( eq(myTable.identifier, params.identifier),...

query based on deep relations

I need help modifying the query code to properly query the chat where it has the the two members. ```ts export const findOrCreateChat = async (fromID: number, toID: number) => { const existingchat = await db.query.chats.findFirst({ with: { members: true },...

transaction is not defined

When calling
const transaction = await db.transaction()
const transaction = await db.transaction()
it returns an error
TypeError: transaction is not a function
TypeError: transaction is not a function
This is my db file...

How do I join the tables of two columns, if both of them point to the same table?

Given the following schema: ```ts export const potentialDuplicate = pgTable( "PotentialDuplicate", {...
No description

Object literal may only specify known properties, and isActive does not exist in type

Some columns are not allowed on update. What am I doing wrong? Schema: ```ts export const prices = pgTable('prices', {...
No description

Is it possible to make this query typesafe?

I needed one more data from the same table. I decided to go with self join following the aliased table method. But it the type for result is never. Maybe it's because of custom query, i m using. The result is as expected but the problem is the type of result. Is there a way I can make it more type safe?...
No description

customType and it's internal types - implementing tsid

I would like to realize a tsid support within my project with drizzle. It's similar to snowflake and its stored in the db as an bigint that with the help of a little library get's converted to a crockford's base32 string. ``` import { customType } from 'drizzle-orm/pg-core'; import { TSID } from 'tsid-ts';...

Filter on joined (with) tables

Is there any way to filter in a way like these using findFirst/findMany? (yes, screenshotting is not a good practice, sorry) So basically I'm joining the "types" table (with: type). I only want to get entries where "types.slug" equals "test"...
No description

Need help building up a query based on nested fields.

I need some help to query the chat that has only the two members only private chat based on the schema below.

Multiple databases

I am planning a new feature at work to make use of multiple databases on the same RDS cluster. Each DB will have a separate schema. Can drizzle handle querying multiple databases? Does anyone have a good example of using Drizzle with the MySql driver configured to query across multiple DBs?...

Drizzle + Sqlite vs Desc index?

I can't seem to find a way to declare a desc index using drizzle with sqlite?

Sharing a database - Keeps trying to drop other tables when pushing tables with the different prefix

So I've got tables with the prefix chris-woodward-gallery and cars-under-20k. I was learning, and still am, so want to make the use of vercel's free db. Problem is I've set up my schema to prefix the tables, and removed any reference to the chris-woodward-gallery variant, but when I push it still say it's trying to drop those tables. ...

Zod error after running introspect which leads to a ton of TS errors in generated schema.

Has anyone run into this error?: ```% npm run drizzle:introspect
revocruit-data@1.0.0 drizzle:introspect...

Issue with json object prop query

This will work but I cant make the 'slug' dynamic ``ts // This works sqlcategories_subquery.categories::jsonb @> jsonb_build_array(jsonb_build_object('slug', ${filter.value}::text))`;...

How do I order by average rating?

I have a table of facilities and reviews for facilities which I can join via the facilityTable.id = review.facilityId columns. I want to select the top ten according to average reviews. How can I do that? Here's what I have so far: ```ts const facilities = await db .select({...