1
votes

I have been researching Firebase as an alternative to the recently deprecated Dropbox Datastore API. I read the articles about structuring data, but I’m still a little unclear.

I have a bunch of users:

users
- name
- email

...and each user has three database “tables”, aircraft, entries, and customFields.

aircraft
- name
- category
- make

entries
- flightDate
- departure
- destination

customFields
- name
- type

So would my Firebase data structure look something like this?

{
    “users”: {
        “bob”: {
            “name”: …
            “email”: …
        },
        “sally”: {
            “name”: …
            “email”: …
        }
    },
    “aircraft”:{
        ???
    },
    “entries”:{
        ???
    },
    “customFields”:{
        ???
    }
}

Thanks in advance.

1
A good article to evaluate if a denormalized model is appropriate for your project: firebase.com/blog/2013-04-12-denormalizing-is-normal.html - Saeed D.

1 Answers

1
votes

Are you familiar with OOP? Each "table" is an object. Personally I would do something as follows. Since I don't understand what you're trying to achieve with the database and their objects, this may not be correct:

{
  "user": {
    "name": "bob",
    "aircraft": {
      "name": "name"
    },
    "entries": {
      "flightdate": "27/05/2015"
    }
  }
}

Think in objects, not tables. Think parent and child.

But in your example, if each object (user, aircraft, entries etc.) was plurals, you can treat them as a "table", it would just be an array of objects:

{
  "aircrafts":[
    {
      "id":1,
      "name": "name"
    },
    {
      "id":2,
      "name": "name"
    }
  ]
}

Edit: My first example was if each user had an aircraft, in retrospect it was silly, but my point still stands.