New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
findAndCountAll and Incrementing certain values of an instance #50
Comments
Not really yet - but it should be easy to put a method like that together do yourself: Projects = Bookshelf.Collection.extend({
findAndCountAll: function(modifiers) {
var knex = Bookshelf.Knex(_.result(this, 'tableName'));
return when.all([
this.query(modifiers).fetch(),
knex.where.apply(knex, modifiers.where).count('*')
]).then(function(resp) {
return {
rows: resp[0],
count: resp[1][0].aggregate
};
});
}
});
projects.findAndCountAll({where: ['title', 'like', 'foo%'], offset: 10, limit: 2}).then(... pretty sure that or something like that should work, didn't test it or anything... Also, you may want to look at increment. user.query().increment('versionNumber').then(... |
|
I'm not sure I follow, would this work? var User = Bookshelf.Model.extend({
increment: function(where, count) {
count = count || 1;
return this.query().where(where).increment('field', count)
}
}); then: user.increment(['id', '>', 10]).then(... |
Sorry I was not very clear. What I meant was this:
|
My general inclination is that this is something best accomplished with custom method: incrementLogin: function() {
var model = this;
return this.query()
.where(id, this.id)
.update(_.extend(this.omit('logins'), {logins: Knex.Raw('logins + 1')})
.then(function() {
return model;
});
} But I could consider adding something like this in the future... I just don't want to clutter the bookshelf api with too many things that could be accomplished fairly easily by dropping down to the Knex layer. user.incrementLogin().then(... |
@tgriesser Is |
Yes, lowercase |
(from Sequelize) Really need findAndCountAll for paging. Get total records count with given query and get result with
limit
andoffset
. Any way to do it right now?Incrementing a column value without running into concurrency issues. Like:
The text was updated successfully, but these errors were encountered: