mirror of
https://github.com/knex/knex.git
synced 2025-12-28 15:38:41 +00:00
Increment floats (#2614)
* Fix increment/decrement with float values * parse float in mariadb * mysql produces float(8, 2), not double
This commit is contained in:
parent
51e44052b4
commit
db390b11e6
@ -142,6 +142,8 @@ function parseType(value, type) {
|
||||
return new Date(value);
|
||||
case 'INTEGER':
|
||||
return parseInt(value, 10);
|
||||
case 'FLOAT':
|
||||
return parseFloat(value);
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -932,7 +932,7 @@ assign(Builder.prototype, {
|
||||
|
||||
// Helper for the incrementing/decrementing queries.
|
||||
_counter(column, amount, symbol) {
|
||||
let amt = parseInt(amount, 10);
|
||||
let amt = parseFloat(amount);
|
||||
if (isNaN(amt)) amt = 1;
|
||||
this._method = 'counter';
|
||||
this._single.counter = {
|
||||
|
||||
@ -458,7 +458,7 @@ module.exports = function(knex) {
|
||||
}).then(function() {
|
||||
return knex.select('*').from('accounts').first();
|
||||
}).then(function(resp) {
|
||||
expect(_.keys(resp).sort()).to.eql(["about", "created_at", "email", "id", "last_name", "logins", "phone", "updated_at"]);
|
||||
expect(_.keys(resp).sort()).to.eql(["about", "balance", "created_at", "email", "id", "last_name", "logins", "phone", "updated_at"]);
|
||||
}).then(function() {
|
||||
return knex.count('*').from('accounts');
|
||||
}).then(function(resp) {
|
||||
|
||||
@ -20,6 +20,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -31,6 +32,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -42,6 +44,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -59,6 +62,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -71,6 +75,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -83,6 +88,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -101,6 +107,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -113,6 +120,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -125,6 +133,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -141,6 +150,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -152,6 +162,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -163,6 +174,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -178,6 +190,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -189,6 +202,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -200,6 +214,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -215,6 +230,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -226,6 +242,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -237,6 +254,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -262,6 +280,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -273,6 +292,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -284,6 +304,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -295,6 +316,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test4@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -306,6 +328,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test5@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -317,6 +340,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test6@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -334,6 +358,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -346,6 +371,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -358,6 +384,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -370,6 +397,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test4@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -382,6 +410,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test5@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -394,6 +423,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test6@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -412,6 +442,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -424,6 +455,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -436,6 +468,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -448,6 +481,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test4@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -460,6 +494,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test5@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -472,6 +507,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test6@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -488,6 +524,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -499,6 +536,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -510,6 +548,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -521,6 +560,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test4@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -532,6 +572,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test5@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -543,6 +584,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test6@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -558,6 +600,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -569,6 +612,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -580,6 +624,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -591,6 +636,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test4@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -602,6 +648,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test5@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -613,6 +660,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test6@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -628,6 +676,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -639,6 +688,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -650,6 +700,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -661,6 +712,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test4@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -672,6 +724,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test5@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -683,6 +736,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test6@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -709,6 +763,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -723,6 +778,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -737,6 +793,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -751,6 +808,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test4@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -765,6 +823,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test5@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -779,6 +838,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test6@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -799,6 +859,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -814,6 +875,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -829,6 +891,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -844,6 +907,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test4@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -859,6 +923,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test5@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -874,6 +939,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test6@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -895,6 +961,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -910,6 +977,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -925,6 +993,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -940,6 +1009,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test4@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -955,6 +1025,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test5@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -970,6 +1041,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test6@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -989,6 +1061,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -1003,6 +1076,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -1017,6 +1091,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -1031,6 +1106,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test4@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -1045,6 +1121,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test5@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -1059,6 +1136,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test6@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -1077,6 +1155,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -1091,6 +1170,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test2@example.com',
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -1105,6 +1185,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test3@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -1119,6 +1200,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test4@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -1133,6 +1215,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test5@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -1147,6 +1230,7 @@ module.exports = function(knex) {
|
||||
last_name: 'User',
|
||||
email: 'test6@example.com',
|
||||
logins: 2,
|
||||
balance: 0,
|
||||
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
|
||||
@ -499,6 +499,7 @@ module.exports = function(knex) {
|
||||
last_name: "User",
|
||||
email: "test@example.com",
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: "Lorem ipsum Dolore labore incididunt enim.",
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -515,6 +516,7 @@ module.exports = function(knex) {
|
||||
last_name: "User",
|
||||
email: "test@example.com",
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: "Lorem ipsum Dolore labore incididunt enim.",
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -531,6 +533,7 @@ module.exports = function(knex) {
|
||||
last_name: "User",
|
||||
email: "test@example.com",
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: "Lorem ipsum Dolore labore incididunt enim.",
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -547,6 +550,7 @@ module.exports = function(knex) {
|
||||
last_name: "User",
|
||||
email: "test@example.com",
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: "Lorem ipsum Dolore labore incididunt enim.",
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -563,6 +567,7 @@ module.exports = function(knex) {
|
||||
last_name: "User",
|
||||
email: "test@example.com",
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: "Lorem ipsum Dolore labore incididunt enim.",
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
@ -579,6 +584,7 @@ module.exports = function(knex) {
|
||||
last_name: "User",
|
||||
email: "test@example.com",
|
||||
logins: 1,
|
||||
balance: 0,
|
||||
about: "Lorem ipsum Dolore labore incididunt enim.",
|
||||
created_at: d,
|
||||
updated_at: d,
|
||||
|
||||
@ -92,6 +92,17 @@ module.exports = function(knex) {
|
||||
});
|
||||
});
|
||||
|
||||
it('should increment a float value', function() {
|
||||
return knex('accounts').select('balance').where('id', 1).then(function(accounts) {
|
||||
return knex('accounts').where('id', 1).increment('balance', 22.53).then(function(rowsAffected) {
|
||||
expect(rowsAffected).to.equal(1);
|
||||
return knex('accounts').select('balance').where('id', 1);
|
||||
}).then(function(accounts2) {
|
||||
expect(accounts[0].balance + 22.53).to.be.closeTo(accounts2[0].balance, 0.001);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should decrement a value', function() {
|
||||
return knex('accounts').select('logins').where('id', 1).then(function(accounts) {
|
||||
return knex('accounts').where('id', 1).decrement('logins').then(function(rowsAffected) {
|
||||
@ -114,6 +125,17 @@ module.exports = function(knex) {
|
||||
});
|
||||
});
|
||||
|
||||
it('should decrement a float value', function() {
|
||||
return knex('accounts').select('balance').where('id', 1).then(function(accounts) {
|
||||
return knex('accounts').where('id', 1).decrement('balance', 10.29).then(function(rowsAffected) {
|
||||
expect(rowsAffected).to.equal(1);
|
||||
return knex('accounts').select('balance').where('id', 1);
|
||||
}).then(function(accounts2) {
|
||||
expect(accounts[0].balance - 10.29).to.be.closeTo(accounts2[0].balance, 0.001);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow returning for updates in postgresql', function() {
|
||||
|
||||
return knex('accounts').where('id', 1).update({
|
||||
|
||||
@ -222,6 +222,7 @@ module.exports = function(knex) {
|
||||
table.string('last_name');
|
||||
table.string('email').unique().nullable();
|
||||
table.integer('logins').defaultTo(1).index().comment();
|
||||
table.float('balance').defaultTo(0);
|
||||
if (knex.client.dialect === 'oracle') {
|
||||
// use string instead to force varchar2 to avoid later problems with join and union
|
||||
table.string('about', 4000).comment('A comment.');
|
||||
@ -230,22 +231,23 @@ module.exports = function(knex) {
|
||||
}
|
||||
table.timestamps();
|
||||
}).testSql(function(tester) {
|
||||
tester('mysql', ['create table `test_table_one` (`id` bigint unsigned not null auto_increment primary key, `first_name` varchar(255), `last_name` varchar(255), `email` varchar(255) null, `logins` int default \'1\', `about` text comment \'A comment.\', `created_at` datetime, `updated_at` datetime) default character set utf8 engine = InnoDB comment = \'A table comment.\'','alter table `test_table_one` add index `test_table_one_first_name_index`(`first_name`)','alter table `test_table_one` add unique `test_table_one_email_unique`(`email`)','alter table `test_table_one` add index `test_table_one_logins_index`(`logins`)']);
|
||||
tester('mysql', ['create table `test_table_one` (`id` bigint unsigned not null auto_increment primary key, `first_name` varchar(255), `last_name` varchar(255), `email` varchar(255) null, `logins` int default \'1\', `balance` float(8, 2) default \'0\', `about` text comment \'A comment.\', `created_at` datetime, `updated_at` datetime) default character set utf8 engine = InnoDB comment = \'A table comment.\'','alter table `test_table_one` add index `test_table_one_first_name_index`(`first_name`)','alter table `test_table_one` add unique `test_table_one_email_unique`(`email`)','alter table `test_table_one` add index `test_table_one_logins_index`(`logins`)']);
|
||||
tester('redshift', ['create table "test_table_one" FOOBAR']);
|
||||
tester('pg', ['create table "test_table_one" ("id" bigserial primary key, "first_name" varchar(255), "last_name" varchar(255), "email" varchar(255) null, "logins" integer default \'1\', "about" text, "created_at" timestamptz, "updated_at" timestamptz)','comment on table "test_table_one" is \'A table comment.\'',"comment on column \"test_table_one\".\"logins\" is NULL",'comment on column "test_table_one"."about" is \'A comment.\'','create index "test_table_one_first_name_index" on "test_table_one" ("first_name")','alter table "test_table_one" add constraint "test_table_one_email_unique" unique ("email")','create index "test_table_one_logins_index" on "test_table_one" ("logins")']);
|
||||
tester('pg-redshift', ['create table "test_table_one" ("id" bigint identity(1,1) primary key not null, "first_name" varchar(255), "last_name" varchar(255), "email" varchar(255) null, "logins" integer default \'1\', "about" varchar(max), "created_at" timestamptz, "updated_at" timestamptz)','comment on table "test_table_one" is \'A table comment.\'',"comment on column \"test_table_one\".\"logins\" is NULL",'comment on column "test_table_one"."about" is \'A comment.\'','alter table "test_table_one" add constraint "test_table_one_email_unique" unique ("email")']);
|
||||
tester('sqlite3', ['create table `test_table_one` (`id` integer not null primary key autoincrement, `first_name` varchar(255), `last_name` varchar(255), `email` varchar(255) null, `logins` integer default \'1\', `about` text, `created_at` datetime, `updated_at` datetime)','create index `test_table_one_first_name_index` on `test_table_one` (`first_name`)','create unique index `test_table_one_email_unique` on `test_table_one` (`email`)','create index `test_table_one_logins_index` on `test_table_one` (`logins`)']);
|
||||
tester('pg', ['create table "test_table_one" ("id" bigserial primary key, "first_name" varchar(255), "last_name" varchar(255), "email" varchar(255) null, "logins" integer default \'1\', "balance" real default \'0\', "about" text, "created_at" timestamptz, "updated_at" timestamptz)','comment on table "test_table_one" is \'A table comment.\'',"comment on column \"test_table_one\".\"logins\" is NULL",'comment on column "test_table_one"."about" is \'A comment.\'','create index "test_table_one_first_name_index" on "test_table_one" ("first_name")','alter table "test_table_one" add constraint "test_table_one_email_unique" unique ("email")','create index "test_table_one_logins_index" on "test_table_one" ("logins")']);
|
||||
tester('pg-redshift', ['create table "test_table_one" ("id" bigint identity(1,1) primary key not null, "first_name" varchar(255), "last_name" varchar(255), "email" varchar(255) null, "logins" integer default \'1\', "balance" real default \'0\', "about" varchar(max), "created_at" timestamptz, "updated_at" timestamptz)','comment on table "test_table_one" is \'A table comment.\'',"comment on column \"test_table_one\".\"logins\" is NULL",'comment on column "test_table_one"."about" is \'A comment.\'','alter table "test_table_one" add constraint "test_table_one_email_unique" unique ("email")']);
|
||||
tester('sqlite3', ['create table `test_table_one` (`id` integer not null primary key autoincrement, `first_name` varchar(255), `last_name` varchar(255), `email` varchar(255) null, `logins` integer default \'1\', `balance` float default \'0\', `about` text, `created_at` datetime, `updated_at` datetime)','create index `test_table_one_first_name_index` on `test_table_one` (`first_name`)','create unique index `test_table_one_email_unique` on `test_table_one` (`email`)','create index `test_table_one_logins_index` on `test_table_one` (`logins`)']);
|
||||
tester('oracle', [
|
||||
'create table "test_table_one" ("id" number(20, 0) not null primary key, "first_name" varchar2(255), "last_name" varchar2(255), "email" varchar2(255) null, "logins" integer default \'1\', "about" varchar2(4000), "created_at" timestamp with time zone, "updated_at" timestamp with time zone)',
|
||||
'create table "test_table_one" ("id" number(20, 0) not null primary key, "first_name" varchar2(255), "last_name" varchar2(255), "email" varchar2(255) null, "logins" integer default \'1\', "balance" float default \'0\',"about" varchar2(4000), "created_at" timestamp with time zone, "updated_at" timestamp with time zone)',
|
||||
'comment on table "test_table_one" is \'A table comment.\'',
|
||||
"begin execute immediate 'create sequence \"test_table_one_seq\"'; exception when others then if sqlcode != -955 then raise; end if; end;",
|
||||
"create or replace trigger \"test_table_one_id_trg\" before insert on \"test_table_one\" for each row when (new.\"id\" is null) begin select \"test_table_one_seq\".nextval into :new.\"id\" from dual; end;",
|
||||
"comment on column \"test_table_one\".\"logins\" is \'\'",
|
||||
"comment on column \"test_table_one\".\"balance\" is \'\'",
|
||||
'comment on column "test_table_one"."about" is \'A comment.\'',
|
||||
'create index "NkZo/dGRI9O73/NE2fHo+35d4jk" on "test_table_one" ("first_name")',
|
||||
'alter table "test_table_one" add constraint "test_table_one_email_unique" unique ("email")',
|
||||
'create index "test_table_one_logins_index" on "test_table_one" ("logins")']);
|
||||
tester('mssql', ['CREATE TABLE [test_table_one] ([id] bigint identity(1,1) not null primary key, [first_name] nvarchar(255), [last_name] nvarchar(255), [email] nvarchar(255) null, [logins] int default \'1\', [about] nvarchar(max), [created_at] datetime, [updated_at] datetime, CONSTRAINT [test_table_one_email_unique] UNIQUE ([email]))',
|
||||
tester('mssql', ['CREATE TABLE [test_table_one] ([id] bigint identity(1,1) not null primary key, [first_name] nvarchar(255), [last_name] nvarchar(255), [email] nvarchar(255) null, [logins] int default \'1\', [balance] decimal default \'0\', [about] nvarchar(max), [created_at] datetime, [updated_at] datetime, CONSTRAINT [test_table_one_email_unique] UNIQUE ([email]))',
|
||||
'CREATE INDEX [test_table_one_first_name_index] ON [test_table_one] ([first_name])',
|
||||
'CREATE INDEX [test_table_one_logins_index] ON [test_table_one] ([logins])']);
|
||||
});
|
||||
|
||||
@ -4101,6 +4101,90 @@ describe("QueryBuilder", function() {
|
||||
});
|
||||
});
|
||||
|
||||
it("increment method", function() {
|
||||
testsql(qb().into('users').where('id', '=', 1).increment('balance', 10), {
|
||||
mysql: {
|
||||
sql: 'update `users` set `balance` = `balance` + 10 where `id` = ?',
|
||||
bindings: [1]
|
||||
},
|
||||
mssql: {
|
||||
sql: 'update [users] set [balance] = [balance] + 10 where [id] = ?;select @@rowcount',
|
||||
bindings: [1]
|
||||
},
|
||||
postgres: {
|
||||
sql: 'update "users" set "balance" = "balance" + 10 where "id" = ?',
|
||||
bindings: [1]
|
||||
},
|
||||
redshift: {
|
||||
sql: 'update "users" set "balance" = "balance" + 10 where "id" = ?',
|
||||
bindings: [1]
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("increment method with floats", function() {
|
||||
testsql(qb().into('users').where('id', '=', 1).increment('balance', 1.23), {
|
||||
mysql: {
|
||||
sql: 'update `users` set `balance` = `balance` + 1.23 where `id` = ?',
|
||||
bindings: [1]
|
||||
},
|
||||
mssql: {
|
||||
sql: 'update [users] set [balance] = [balance] + 1.23 where [id] = ?;select @@rowcount',
|
||||
bindings: [1]
|
||||
},
|
||||
postgres: {
|
||||
sql: 'update "users" set "balance" = "balance" + 1.23 where "id" = ?',
|
||||
bindings: [1]
|
||||
},
|
||||
redshift: {
|
||||
sql: 'update "users" set "balance" = "balance" + 1.23 where "id" = ?',
|
||||
bindings: [1]
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("decrement method", function() {
|
||||
testsql(qb().into('users').where('id', '=', 1).decrement('balance', 10), {
|
||||
mysql: {
|
||||
sql: 'update `users` set `balance` = `balance` - 10 where `id` = ?',
|
||||
bindings: [1]
|
||||
},
|
||||
mssql: {
|
||||
sql: 'update [users] set [balance] = [balance] - 10 where [id] = ?;select @@rowcount',
|
||||
bindings: [1]
|
||||
},
|
||||
postgres: {
|
||||
sql: 'update "users" set "balance" = "balance" - 10 where "id" = ?',
|
||||
bindings: [1]
|
||||
},
|
||||
redshift: {
|
||||
sql: 'update "users" set "balance" = "balance" - 10 where "id" = ?',
|
||||
bindings: [1]
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("decrement method with floats", function() {
|
||||
testsql(qb().into('users').where('id', '=', 1).decrement('balance', 1.23), {
|
||||
mysql: {
|
||||
sql: 'update `users` set `balance` = `balance` - 1.23 where `id` = ?',
|
||||
bindings: [1]
|
||||
},
|
||||
mssql: {
|
||||
sql: 'update [users] set [balance] = [balance] - 1.23 where [id] = ?;select @@rowcount',
|
||||
bindings: [1]
|
||||
},
|
||||
postgres: {
|
||||
sql: 'update "users" set "balance" = "balance" - 1.23 where "id" = ?',
|
||||
bindings: [1]
|
||||
},
|
||||
redshift: {
|
||||
sql: 'update "users" set "balance" = "balance" - 1.23 where "id" = ?',
|
||||
bindings: [1]
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("delete method", function() {
|
||||
testsql(qb().from('users').where('email', '=', 'foo').delete(), {
|
||||
mysql: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user