Comparing version 0.10.4 to 0.10.5
@@ -87,9 +87,19 @@ /** | ||
// Going backwards so that the first sort is the last that gets applied | ||
for (i = keys.length - 1; i >= 0; i -= 1) { | ||
// Sorting | ||
var criteria = []; | ||
for (i = 0; i < keys.length; i++) { | ||
key = keys[i]; | ||
res.sort(function(a, b) { | ||
return self._sort[key] * model.compareThings(model.getDotValue(a, key), model.getDotValue(b, key)); | ||
}); | ||
criteria.push({ key: key, direction: self._sort[key] }); | ||
} | ||
res.sort(function(a, b) { | ||
var criterion, compare, i; | ||
for (i = 0; i < criteria.length; i++) { | ||
criterion = criteria[i]; | ||
compare = criterion.direction * model.compareThings(model.getDotValue(a, criterion.key), model.getDotValue(b, criterion.key)); | ||
if (compare !== 0) { | ||
return compare; | ||
} | ||
} | ||
return 0; | ||
}); | ||
@@ -96,0 +106,0 @@ // Applying limit and skip |
@@ -158,5 +158,7 @@ /** | ||
Persistence.prototype.setAutocompactionInterval = function (interval) { | ||
var self = this; | ||
var self = this | ||
, minInterval = 5000 | ||
, realInterval = Math.max(interval || 0, minInterval) | ||
; | ||
if (interval < 5000) { interval = 5000; } | ||
this.stopAutocompaction(); | ||
@@ -166,3 +168,3 @@ | ||
self.compactDatafile(); | ||
}, interval); | ||
}, realInterval); | ||
}; | ||
@@ -169,0 +171,0 @@ |
{ | ||
"name": "nedb", | ||
"version": "0.10.4", | ||
"version": "0.10.5", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Louis Chatriot", |
@@ -15,3 +15,3 @@ # NeDB (Node embedded database) | ||
You want to help out? Check out how! | ||
You want to help out? <a href="#contribute">You can contribute time or bitcoins, check out how!</a> | ||
@@ -104,3 +104,3 @@ | ||
You can manually call the compaction function with `yourDatabase.persistence.compactDatafile` which takes a `callback(err)` as argument. | ||
You can manually call the compaction function with `yourDatabase.persistence.compactDatafile` which takes no argument. It queues a compaction of the datafile in the executor, to be executed sequentially after all pending operations. | ||
@@ -122,3 +122,3 @@ You can also set automatic compaction at regular intervals with `yourDatabase.persistence.setAutocompactionInterval(interval)`, `interval` in milliseconds (a minimum of 5s is enforced), and stop automatic compaction with `yourDatabase.persistence.stopAutocompaction()`. | ||
```javascript | ||
var document = { hello: 'world' | ||
var doc = { hello: 'world' | ||
, n: 5 | ||
@@ -133,3 +133,3 @@ , today: new Date() | ||
db.insert(document, function (err, newDoc) { // Callback is optional | ||
db.insert(doc, function (err, newDoc) { // Callback is optional | ||
// newDoc is the newly inserted document, including its _id | ||
@@ -592,6 +592,12 @@ // newDoc has no key called notToBeSaved since its value was undefined | ||
## Help out! | ||
## Contribute! | ||
You want to help? You can contribute time or bitcoins. | ||
### Helping on the codebase | ||
Issues reporting and pull requests are always appreciated. For issues, make sure to always include a code snippet and describe the expected vs actual behavior. If you send a pull request, make sure to stick to NeDB's coding style and always test all the code you submit. You can look at the current tests to see how to do it | ||
### Bitcoins | ||
You don't have time? You can support NeDB by sending bitcoins to this adress: 1dDZLnWpBbodPiN8sizzYrgaz5iahFyb1 | ||
## License | ||
@@ -598,0 +604,0 @@ |
@@ -607,3 +607,48 @@ var should = require('chai').should() | ||
], done); }); | ||
it('Similar data, multiple consecutive sorts', function(done) { | ||
var i, j, id | ||
, companies = [ 'acme', 'milkman', 'zoinks' ] | ||
, entities = [] | ||
; | ||
async.waterfall([ | ||
function (cb) { | ||
d.remove({}, { multi: true }, function (err) { | ||
if (err) { return cb(err); } | ||
id = 1; | ||
for (i = 0; i < companies.length; i++) { | ||
for (j = 5; j <= 100; j += 5) { | ||
entities.push({ | ||
company: companies[i], | ||
cost: j, | ||
nid: id | ||
}); | ||
id++; | ||
} | ||
} | ||
async.each(entities, function(entity, callback) { | ||
d.insert(entity, function() { | ||
callback(); | ||
}); | ||
}, function(err) { | ||
return cb(); | ||
}); | ||
}); | ||
} | ||
, function (cb) { | ||
var cursor = new Cursor(d, {}); | ||
cursor.sort({ company: 1, cost: 1 }).exec(function (err, docs) { | ||
docs.length.should.equal(60); | ||
for (var i = 0; i < docs.length; i++) { | ||
docs[i].nid.should.equal(i+1); | ||
}; | ||
return cb(); | ||
}); | ||
} | ||
], done); }); | ||
}); // ===== End of 'Sorting' ===== | ||
@@ -610,0 +655,0 @@ |
711670
16650
622