Skip to content

Commit b851dc9

Browse files
committed
Adds chainfind.first() to run and return only the first result (or null if none)
1 parent 04a6cac commit b851dc9

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎lib/ChainFind.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ function ChainFind(opts) {
6262
});
6363
return this;
6464
},
65+
first: function (cb) {
66+
return this.run(function (err, items) {
67+
return cb(err, items.length > 0 ? items[0] : null);
68+
});
69+
},
6570
run: function (cb) {
6671
opts.driver.find(opts.only, opts.table, opts.conditions, {
6772
limit : opts.limit,

0 commit comments

Comments
 (0)