-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstorage.js
More file actions
38 lines (27 loc) · 816 Bytes
/
storage.js
File metadata and controls
38 lines (27 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var mongoose = require('mongoose'),
when = require('when'),
nodefn = require('when/node');
var scoreSchema = new mongoose.Schema({
score: Number
});
var Score = mongoose.model("Score", scoreSchema);
function Storage() {}
Storage.prototype.setup = function() {
return nodefn.call(mongoose.connect.bind(mongoose), 'localhost');
}
Storage.prototype.disconnect = function() {
mongoose.disconnect();
}
Storage.prototype.populate = function(score) {
var model = new Score();
model.score = score;
return nodefn.call(model.save.bind(model));
}
Storage.prototype.score = function() {
var deferred = when.defer();
Score.where().findOneAndRemove(nodefn.createCallback(deferred.resolver));
return deferred.promise.then(function(doc) {
return doc.score;
});
}
module.exports = Storage;