Drizzle Team

DT

Drizzle Team

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

Join

Doent infer type in Callback syntax for query

Im querying the users table like this `db.query.user.findFirst({ where: (user, { eq }) => { return eq(user.email, whereArgs?.email); },...

Bug When Trying To Increment A Field

this set the field to 0 instead of increasing by one it used to work in other routes ``` await db .update(Artists)...

Maximum call stack exceeded with relation to self

I have the following table ``` export const category = pgTable('categories', { id: serial('id').primaryKey().notNull(), parentCategoryId: integer('parent_category_id').references((): AnyPgColumn => category.id)...

importing into schema.ts file

Hi, I am using turborepo and I have defined my schema in packages/schema/user.ts and in my main API application apps/api/schema.ts I import the user schema. I believe I have everything setup correctly in terms of package.json setup. My problem is that when using running migrations only tables explicitly defined in schema.ts seem to work. ...

What versions of MySQL are supported? I have JSON_ARRAYAGG issues with 5.7 and AWS Aurora Serverless

Can you confirm what versions of MySQL you intend on supporting? Relational queries with joins use JSON_ARRAYAGG which is not supported by earlier versions of 5.7 including AWS Aurora Serverless v1.

`$with` example in docs error "unsupported: with expression in select statement"

I have a user with id of 42, just like the docs https://orm.drizzle.team/docs/crud#with-clause but executing the same query throws an Error: unsupported: with expression in select statement ```ts const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)))...

Infer type for relational query

Is there anyway to infer the type of a relational queries result? For example if I have a user who makes posts which has comments. I have a relational query which gets me all my users, their posts and their comments nested. Is there a way to infer that type? Currently constructing the type myself from the tables in the schema.

in drizzle.config.ts: "Cannot use import statement outside a module"

happens when I try to push ```ts import type { Config } from "drizzle-kit"; import { env } from "~/env.mjs";...

Error when using Drizzle (Non-abstract class 'PgSelect<TTableName, TSelection, TSelectMode, [...])

I'm getting the following error when I try to use Drizzle: ```> [email protected] start
npm run compile && node ./dist/index.js
...

Generate classes/interfaces from existing schemas?

Messing around with drizzle, and I was wondering if there was any way to generate a class or interface derived from an existing schema? My database is currently managed out-of-band (not by drizzle), by another service, so writing schemas by hand again, is not really preferred. I looked around and couldn't find anything related to doing such a task. This would really help a lot when using drizzle.

Relation Query - Get likes in post

Playing around with relational queries and I'm not quite getting how I'd retrieve the count of likes on a given post. I'm able to accomplish this in sql, but I'm having a hard time translating or failing to understand why i cant translate this to drizzle. ...

Relation query `extras` needs access to `with`

I have a mysql table with two relations to another table. (one is for source values, one is for optional admin edited values.) The app logic is "if admin value exists, return admin value, else return source value". (But do not return both, since it would be a large network payload) The relation query easily includes the 2 related columns via with key....

Optional filter param, coalesce to true?

Is there a way to achieve this coalescing technique, but in valid drizzle sql? ```ts const filterByBool: boolean | undefined | null = undefined ...

Relational query, Planetscale throws: `ResourceExhausted desc = Out of sort memory`

SOLUTION: the problem was that I had a json column storing a massive value on each row. code = ResourceExhausted desc = Out of sort memory, consider increasing server sort buffer size (errno 1038) (sqlstate HY001) Possible reasons?...

Int to Float or Double db:push

Hi we are working on a project that has drizzle db connected to a planetscale database. We initially had a column as an integer, but we later on decided that the column should be a float or a double. Doing a db:push truncates the column and deletes all the rows of the table. Is this a bug or is it like that by design? If it's by design what is the best way to update the columns to a double without wiping the table? Thanks in advance.

Timestamp mode differences?

What is the difference between the timestamp "mode" of "string'"and "date"?

Many-to-Many Self Relation

I'm looking to migrate from Prisma, but I'm having trouble trying to figure out how a many-to-many self relation should be defined. The prisma schema I has previously was similar to: ``` model User { id String @id...

Relations, three level nested where?

Given a User, Role, RoleToUser many-to-many relation: ```ts export const userRelations = relations(User, ({ many }) => ({ roleToUser: many(RoleToUser),...

Help with this relational query?

I am trying to get all the organizations that a member is associated with. This code is working: ```js...

RQB | using specific fields from a query against relations

is there a way to create a select filter that matches specific fields from a relation? say i findMany on posts and want to select all the posts where a relational one-to-many tags.name is inArray of a tagList array...