title: What is the simplest way to save a file-tree in a postgres database?
body: <p>I'm retrieving a file-tree from the dropbox api. In the api every folder is read with a  separate, api call, so I will iterate through the entire file-tree to get all the folders. This is done with a cron-job.</p>
  
  <p>The function that retrievs the data from dropbox looks like this:</p>
  
  <pre><code>function renderFolderTree($myobject, $path){
      $entry = $myobject-&gt;getMetadataWithChildren($path);
      foreach ($entry['contents'] as $child) {
          if ($child['is_dir']){
              $folderpath = $child['path'];
              //this will retrieve the child-folder
              renderFolderTree($myobject, $folderpath, $filetree);
              //here I need something that saves the folder
          }else{
              print_r($child);
              //here I need something that saves the file
          }
      }
  }
  </code></pre>
  
  <p>I want to save the file-tree to a postgres-database so that it later can be ouputted as a json object that represents it.</p>
  
  <p>I'm new to database design and am not sure what way to save the data. I assume every file and folder should have a database entry of their own. I could let every child reference it's parents ID, or I could let every parent contain a list of it's children.</p>
  
  <p>As I am novice I would like a solution that is reasonably simple and reading speed is much more important than writing!</p>