Last active
January 21, 2016 16:49
-
-
Save penoonan/402d52ecd3f93f15e328 to your computer and use it in GitHub Desktop.
Quick Firebase to Botkit storage adapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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