Skip to content

Instantly share code, notes, and snippets.

@joshholt
Created January 18, 2012 21:03
Show Gist options
  • Save joshholt/1635644 to your computer and use it in GitHub Desktop.
Save joshholt/1635644 to your computer and use it in GitHub Desktop.
Express Route DB Middle ware
var _ = require('underscore');
var insertRecord, fetchRecord, updateRecord, deleteRecord;
insertRecord = function(db, req) {
db[req.params.guid] = '{}';
return "We have inserted a record for the instance represented by the GUID: " + req.params.guid;
};
fetchRecord = function(db, req) {
return db[req.params.guid]
};
updateRecord = function(db, req) {
db[req.params.guid] = JSON.stringify({config: _.extend(req.body, req.query)});
return db[req.params.guid];
};
deleteRecord = function(db, req) {
delete db[req.params.guid];
return "We have removed an instance for you using " + req.params.guid + " as the ID";
};
module.exports = {
createInstance: function(db) { },
configureInstance: function(db) { },
removeInstance: function(db) { },
previewInstance: function(db) { },
renderInstance: function(db) { }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment