Firebase Schema
- Is your firebase code as big a mess as mine usually is?
- Do you not really know what type of data you save at certain paths?
- Do you even know what your data looks like without logging in?
- Can you access foreign keys and indexes easily?
If you answered "..." to any one of these questions this library is right for you.
Usage
Define your paths in one place (hey, this looks like a route config):
var Firebase = ;var FirebaseSchema = ;var string number boolean list hash index key = FirebaseSchemaTypes; var HOST = 'http://example.firebaseio.com'; // pass in Firebase so you can use this on the server or clientvar schema = FirebaseSchema;
- Now its easy to see what kind of data you save and where. Since the schema is defined as a nested route structure, we don't have to leave the key:value paradigm of Firebase.
- Relationships via
index
andkey
get looked up for you (https://www.firebase.com/docs/web/guide/structuring-data.html) - Data is validated when you try to
set
orpush
to a path. list
s are automatically converted to an array when you retrieve the value, with their keys assigned to_id
.
var usersRef = schema;var groupsRef = schema;var userId;var groupId; usersRef; // later groupsRef; // error! should be a string groupsRef; // later groupsRef; // keys work similarlyvar coolKidMessages = schema;coolKidMessages; // latercoolKidMessages;
That's it. That's where this is at. I haven't used it yet in my app, but
am going to soon, will probably need to add in some more of the firebase
API to createRef
. In the meantime, check out tests.js
to see
anything I've missed here.