1

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.

Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128
  • 2
    A good article to evaluate if a denormalized model is appropriate for your project: https://www.firebase.com/blog/2013-04-12-denormalizing-is-normal.html – Saeed D. Apr 29 '15 at 13:31

1 Answers1

1

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.

ZeroBased_IX
  • 2,667
  • 2
  • 25
  • 46
  • Perhaps it would help if I clarify some things. Each user has many aircraft (an array of aircraft) and many entries (thousands in an array of entries). – Clifton Labrum Apr 27 '15 at 22:04
  • That's fine, if you combine both my examples you should get where you need to go. Use the second example for the basis of both entries and aircraft. You can store them as such. You can nest and store as many as you wish. One concern I have is that Firebase may not be the platform for you if there are as many records as you say. I'm no expert on Firebase performance though. – ZeroBased_IX Apr 27 '15 at 22:08
  • I've had the same concern regarding performance. I'm still shopping around for the right sync-able data platform. – Clifton Labrum Apr 27 '15 at 22:14
  • Have you looked at statistics on Firebase performance? It is backed by Google so it has the infrastructure. I would have a look myself but I'm in bed at the moment. I'm curious myself though. If I find something I'll let you know. – ZeroBased_IX Apr 27 '15 at 22:15
  • Apparently Firebase is designed for large datasets. http://stackoverflow.com/a/16240601. That is the design you should be aiming for. – ZeroBased_IX Apr 28 '15 at 06:12
  • 1
    Just a side note, you probably want to avoid using arrays. Check out the blog post, [Best Practices: Arrays in Firebase](https://www.firebase.com/blog/2014-04-28-best-practices-arrays-in-firebase.html) - _"Why not just store arrays instead of objects? Arrays are Evil"_ – sbolel May 03 '15 at 01:54