|
|
@ -130,15 +130,32 @@ Datastore.prototype.find = function (query, callback) { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Find one document matching the query |
|
|
|
|
|
|
|
* @param {Object} query MongoDB-style query |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
Datastore.prototype.findOne = function (query, callback) { |
|
|
|
|
|
|
|
var self = this |
|
|
|
|
|
|
|
, i |
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < self.data.length; i += 1) { |
|
|
|
|
|
|
|
if (Datastore.match(self.data[i], query)) { |
|
|
|
|
|
|
|
return callback(null, self.data[i]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return callback(null, null); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var d = new Datastore('workspace/test.db'); |
|
|
|
var d = new Datastore('workspace/test.db'); |
|
|
|
d.loadDatabase(function (err) { |
|
|
|
d.loadDatabase(function (err) { |
|
|
|
console.log(d.data); |
|
|
|
console.log(d.data); |
|
|
|
d.find({ te: "un" }, function (err, docs) { |
|
|
|
|
|
|
|
console.log(err); |
|
|
|
|
|
|
|
console.log('------------------'); |
|
|
|
|
|
|
|
console.log(docs); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|