jsbin/lib/store.js
2012-05-18 15:49:47 +01:00

34 lines
704 B
JavaScript

function Store(options) {
var Adapter = require('./db/' + options.adapter);
this.adapter = new Adapter(options[options.adapter]);
}
// Methods that should be supported by adaptors.
var methods = [
'connect',
'disconnect',
'setBin',
'setBinUser',
'setBinPanel',
'getBin',
'getLatestBin',
'getBinsByUser',
'generateBinId',
'getUser',
'setUser',
'touchLogin',
'updateUserKey'
];
// Proxy the methods through the store.
methods.forEach(function (method) {
Store.prototype[method] = function () {
this.adapter[method].apply(this.adapter, arguments);
};
});
module.exports = function createStore(options) {
return new Store(options);
};
module.exports.Store = Store;