drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
23.84k stars 592 forks source link

[FEATURE]: Drizzle relations with materialized views #2653

Open Acorn221 opened 3 months ago

Acorn221 commented 3 months ago

Describe what you want

Hi everyone, I'd love to be able to use the drizzle relations with materialized views, like:

export const theCoolestView = pgMaterializedView("the_coolest_view", {
  id: text("id").notNull(),
  name: text("name").notNull(),
  entityForeignKey: fk("entity", "entity_foreign_key").notNull(),
}).existing();

export const theCoolestViewRelations = relations(theCoolestView, ({ one }) => ({
  entity: one(entity, {
    fields: [theCoolestView.entityForeignKey],
    references: [entity.id],
  }),
}); 

Is this close on the roadmap?

fredgig commented 3 months ago

There's an open issue (#769) asking for the ability to use the relations API with views (not materialized views specifically but I assume that would cover it).

A PR was opened as well (#1778), but it appears to be on hold since January.

Acorn221 commented 2 months ago

Thanks for linking me to that PR, I hope it gets merged in soon, this would also be very helpful for me!