I'm given a JSON (tree structure JSON) and I'm creating an API that will insert all the data at once into the database (organizations with relations). the organisation may have multiple parents and children.
The JSON look's something like this:
{
"org_name": "organisation",
"childrens": [
{
"org_name": "company tree",
"childrens": [
{
"org_name": "company one"
},
{
"org_name": "company two"
},
{
"org_name": "company three"
}
]
},
{
"org_name": "Big organisation",
"childrens": [
{
"org_name": "company one"
},
{
"org_name": "company two"
},
{
"org_name": "company four"
},
{
"org_name": "company three",
"childrens": [
{
"org_name": "smal farm"
}
]
}
]
}
]
}
my database schema (which I'm thinking)
id | org_name | level | parent
*level - tells at which level we are since this is a tree and helps to plot relations
How do I insert these records into the database with their relations? I need to do this in javascript.