1

So below is a beginning structure to part of my data that im trying to setup for a notes app. This notes app will have the ability to have folder and sub folder, and sub folders with in that folder. Think like a Windows File Explorer type of feel. I'm fairly new to Supabase and new to complex data structures. My idea was to nest the sub folders in a "children" array column/cell. The reason for this is so i could easily map through and render the sub-folder component. My question is this, would this be efficient and the way Supabase is set up does it allow for this, or is there some sort of relation setup i need to do like when i associate a user to this data eventually. Would i want to store maybe the id's in the children array and then make another data call. I know i have unlimited requests but how would this affect my data transfer in the long run do you suspect? Essentially what would be the smartest way to store this data.

const menuItems = [
        {name: "A Test Directory", id: 1, parent_id: null, children: []},
        {
            name: "C Test Directory2", id: 2, parent_id: null, children: [
                {name: "B Test sub-Directory1", id: 5, parent_id: 2, children: []},
                {name: "A Test sub-Directory2", id: 6, parent_id: 2, children: []},
            ]
        },
        {
            name: "B Test Directory3", id: 3, parent_id: null, children: [
                {name: "Test sub-Directory3", id: 7, parent_id: 3, children: []},
            ]
        },
        {
            name: "D Test Directory4", id: 4, parent_id: null, children: [
                {name: "Test sub-Directory4", id: 8, parent_id: 4, children: []},

            ]
        },
    ];
4
  • You should research data normalization. Your proposed structure is a very poor way (imho) to store what you want in a relational database. Commented May 30 at 16:43
  • Ok, so i think if i understand data normalization after a quick google search. It would be best to have one table "folders" and kind of like i've done with the parent_id, that associates in the database, and then in my react code i will grab the "null" parent_id's, then render the rest after... am i understanding this correctly? Commented May 30 at 16:54
  • That would be where I would start. If you want the complete hierarchy you would start with the parent_id Null. However that is not necessary, you can actually start anywhere in the hierarchy. For example you could grab just "C Test Directory2" and it's children. NOTE: you would not have the column "children[]". That is a violation of 1st Normal form. Commented May 30 at 17:03
  • ok i think i got it, thank you! i was making this way more complicated then it had to be :D Commented May 30 at 17:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.