mirror of
https://github.com/knex/knex.git
synced 2025-08-11 10:10:56 +00:00
65 lines
1.4 KiB
JavaScript
65 lines
1.4 KiB
JavaScript
module.exports = function(knex) {
|
|
|
|
describe('Updates', function () {
|
|
|
|
it('should handle updates', function() {
|
|
return knex('accounts')
|
|
.logMe()
|
|
.where('id', 1)
|
|
.update({
|
|
first_name: 'User',
|
|
last_name: 'Test',
|
|
email:'test100@example.com'
|
|
});
|
|
});
|
|
|
|
it('should increment a value', function() {
|
|
|
|
return knex('accounts').select('logins').where('id', 1).tap(function() {
|
|
|
|
return knex('accounts').where('id', 1).increment('logins');
|
|
|
|
}).then(function(attrs1) {
|
|
|
|
return knex('accounts').select('logins').where('id', 1).then(function(attrs2) {
|
|
|
|
expect(attrs1[0].logins).to.equal(attrs2[0].logins - 1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
it('should decrement a value', function() {
|
|
|
|
return knex('accounts').select('logins').where('id', 1).tap(function() {
|
|
|
|
return knex('accounts').where('id', 1).decrement('logins');
|
|
|
|
}).then(function(attrs1) {
|
|
|
|
return knex('accounts').select('logins').where('id', 1).then(function(attrs2) {
|
|
|
|
expect(attrs1[0].logins).to.equal(attrs2[0].logins + 1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('should allow returning for updates in postgresql', function() {
|
|
|
|
return knex('accounts').logMe().where('id', 1).update({
|
|
first_name: 'UpdatedUser',
|
|
last_name: 'UpdatedTest',
|
|
email:'test100@example.com'
|
|
}, '*');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}; |