Skip to content

Instantly share code, notes, and snippets.

@penoonan
Last active January 21, 2016 16:49
Show Gist options
  • Save penoonan/402d52ecd3f93f15e328 to your computer and use it in GitHub Desktop.
Save penoonan/402d52ecd3f93f15e328 to your computer and use it in GitHub Desktop.
Quick Firebase to Botkit storage adapter
var config = require('../config');
var Firebase = require('firebase');
var fireBaseRef = new Firebase(config.firebaseUrl);
module.exports = (function() {
var storage = {};
['teams', 'users', 'channels'].map(function(table) {
storage[table] = {
tableRef: fireBaseRef.child(table),
get: function(id, cb) {
var user = this.tableRef.child(id);
return user.once("value", function(snapshot) {
return cb(null, snapshot.val());
});
},
save: function(item, cb) {
var result = this.tableRef.child(item.id).set(item);
return cb(null, result);
},
all: function(cb) {
return this.tableRef.once("value", function(snapshot) {
return cb(snapshot.val());
});
}
}
});
return storage;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment