1

I want to build a WebApp where the user can create an unlimited deep tree structure JSON object. The goal is to send this hierarchical JSON to the backend and store the nested objects with the parent/child relation in a database.

Setup

  • The chain can contain multiple objects
chain = [
{name: "name1",
 children: []
},
{name: "name2",
 children: []
}]
  • Each object in the chain can contain other objects in the children array:
chain = [
{name: "name1",
 children: [{name: "name1child", children: []}]
},
{name: "name2",
 children: []
}]
  • each object can contain multiple children's
  • the children's can also contain multiple children's

Questions

  1. Is this a good solution for modelling the hierarchy in the frontend? I feel like it gets complex when adding/updating/deleting a deep nested object in the chain. In addition i can only search objects by name in the frontend. Is there a better way than that?

  2. How can these objects be stored in a Database without loosing the hierarchy? Is a relational database suited? What about NoSQL or even GraphDb (I have no experience with Graphs).

I know this question is relatively broad. Is this an appropriate schema for handling this nested structure?

Thanks for your help :)

RobboBo
  • 11
  • 1
  • Hi, you should read about trees (data structure). It may help on what you need. https://en.wikipedia.org/wiki/Tree_(data_structure)#:~:text=A%20tree%20data%20structure%20can,none%20points%20to%20the%20root. – Andres Gardiol Dec 10 '20 at 18:44
  • For your first question, it doesn't seems like a good solution for modelling hierarchy. Also its not clear what you expect to achieve in the frontend. – Andres Gardiol Dec 10 '20 at 18:52
  • Hey, thanks for your reply. The Goal is similar to a hierarchy chart for an organisation. Each employe can have several employees underneath. They can have again several employees underneath and so on... – RobboBo Dec 11 '20 at 08:08
  • I found this usefull article about trees. https://medium.com/@_jmoller/javascript-data-structures-trees-c961297e6482 What about the db? :) Should be fine with a relational db or? – RobboBo Dec 11 '20 at 08:15
  • You can read this question https://stackoverflow.com/questions/935098/database-structure-for-tree-data-structure to better know about the DB side of this problem. Tell me then if that question answer your question – Andres Gardiol Dec 11 '20 at 14:20
  • Yes it does! Thanks for your help! – RobboBo Jan 27 '21 at 18:04

0 Answers0