Schema development guide recommendations

225 views
Skip to first unread message

Eugene Thompson

unread,
Sep 25, 2013, 8:43:12 AM9/25/13
to fireba...@googlegroups.com
I'm looking to give Firebase a try for a relatively simple web application I am writing, but am having some problems getting started. I come from a relational database background and am having to constantly rethink what would normally be givens in my development process.

The biggest issue I am dealing with right now is trying to implement a schema in my database without actual data yet. For example, I want to have a list of users, but if the list is empty, the parent reference (http://mydb/users) ceases to exist. I can't even create it in Fireforge. Any direction here would be greatly appreciated.

A deeper issue could be that I am still approaching it backwards. I want to create the structure my application will use in the database before I build out my model (as all the examples seem to imply), but I wonder if I should start with my model in my application first, then just persist it to Firebase as a persistence mechanism. The problem with that is how to read the initial state of the data model on application start. Do I try to get a reference to "users" in my example and if it isn't there, start from scratch?

So, I'm basically looking for some instruction on the standard processes for using this type of data store.

Thanks,
Gene

Michael "Kato" Wulf

unread,
Sep 26, 2013, 6:14:05 PM9/26/13
to fireba...@googlegroups.com
Hello Eugene,

Being from an RDB background myself, it took me a few tries to develop effective data structures in Firebase. I also enjoy having my data structures mapped before I dive into code. If you have something specific in mind, I'd recommend posting your use case up for review. I'm sure some of the devs on the list have similar structures and could offer advice.

What I find works best with NoSQL, for me, is to mock up sample data in a JavaScript object (i.e. a fixture) and use that directly in my proofs. Since Firebase and most NoSQL offerings are essentially JSON trees, this is a great way to emulate data quickly and test out my nested architectures for pain points.

When I get to the point that I'm ready to try some real code and integrate Firebase, a quick call in the JavaScript console to `new Firebase(URL).set( jsData )` imports it into my test environment as quickly as that. 

I do most of my initial mocking and problem solving on a white board or sheet of notebook paper. The notes typically look about like so:

/user/$uid/ {name, email, etc}
/scene/$scene_id/ {title, revs, public, uid, pid}
/copy/$scene_id/$version/ {text, timestamp}
/messages/$scene_id/ {uid, msg}

(with a few smudges, lots of striking out, and a rare drop of blood or tear stain)

I've also experimented, and had good success when I did, with writing my security rules first. Since I find that implementing an effective security policy is directly linked to a well-thought data structure, they fit naturally together. Once written and generously commented, the rules make a fairly nice architectural map of the data.

However, this is probably best attempted once you've got a good feel of the ins and outs of both security and data structures and I don't think it would have done me any good on my first couple apps.

Firebase will be publishing a blog circa next week talking about converting SQL strategies to Firebase and it will feature some sample data. Keep an eye out for that.

Hope something here helps.

Regards,
Kato


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages