drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: with Recursive referential

Open
#1,215 0 comments 2 reactions 0 assignees View on GitHub
enhancement rqb
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Describe what you want

Hello is there a possibility to have exhaustive recursive with statements or should this be a view?

```ts
export const postKind = pgEnum("post_kind", ["text", "image", "video"]);

export const post = pgTable(
"post",
{
id: serial("id").primaryKey(),
createdAt: timestamp("created_at")
.defaultNow()
.notNull(),
updatedAt: timestamp("updatedAt").defaultNow(),
body: text("body"),
kind: postKind("kind").notNull(),
// children: one to many
}
)

export const postRelations = relations(post, ({ one, many }) => ({
children: many(post),
// parent: one(Element),
}))

type PostTypeFirst = InferModel
export type PostType = PostTypeFirst & {
children?: PostType[]
}

//

db.query.post.findFirst({
where: (ele, { eq }) => (
eq(ele.id, input.id)
),
with: {
children: {
depth: 10 // or depth: 0 for exhaustive
},
},
});
```

thanks.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.