IssueRaiser

Tree structures support

## Problem <!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] --> Hello! There is no real functionality for working with tree structures recursively. It would be awesome if there was a functionality added to define a model & query the most popular hierarchal data structures for relational databases. But for the sake of simplicity and referential integrity, i think the adjacency list support would be the the best choice for the first solid implementation. ## Suggested solution <!-- A clear and concise description of what you want to happen. --> The first thing that comes to my mind is that there needs to be some kind of way to declare that a model inside a schema wants to be a tree node. Simple example: ```typescript model Category TreeNode { // Or: Tree, TreeNode('adjacencyList'), Tree('adjancencyList') id Int @id @default(autoincrement()) name String // Those fields below could be added behind the scenes based on model declaration above // But that would be dependent on experimental schema migration tool, so idk // Anyways, in the case of basic adjacency list, those could be required children Category[] @relation("CategoryToCategory") parent Category? @relation("CategoryToCategory", fields: [parentId], references: [id]) parentId Int? } ``` Then there should be some methods for working with trees. Some basic ones, as an example: * getDescendants * getAncestors * getChildren * getR

Posted by tasops on Dec 8, 2020, 6:25 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,000 issues0 comments

support (Other)

Tree structures support

tasopsDec 8, 2020, 6:25 PM

## Problem <!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] --> Hello! There is no real functionality for working with tree structures recursively. It would be awesome if there was a functionality added to define a model & query the most popular hierarchal data structures for relational databases. But for the sake of simplicity and referential integrity, i think the adjacency list support would be the the best choice for the first solid implementation. ## Suggested solution <!-- A clear and concise description of what you want to happen. --> The first thing that comes to my mind is that there needs to be some kind of way to declare that a model inside a schema wants to be a tree node. Simple example: ```typescript model Category TreeNode { // Or: Tree, TreeNode('adjacencyList'), Tree('adjancencyList') id Int @id @default(autoincrement()) name String // Those fields below could be added behind the scenes based on model declaration above // But that would be dependent on experimental schema migration tool, so idk // Anyways, in the case of basic adjacency list, those could be required children Category[] @relation("CategoryToCategory") parent Category? @relation("CategoryToCategory", fields: [parentId], references: [id]) parentId Int? } ``` Then there should be some methods for working with trees. Some basic ones, as an example: * getDescendants * getAncestors * getChildren * getR

Comments (0)

No comments yet. Start the discussion.

Comment on this issue