additional tests & data for #219

This commit is contained in:
Tim Griesser 2014-03-26 19:15:46 -04:00
parent 1c403a5a40
commit aa47c24568
5 changed files with 109 additions and 36 deletions

View File

@ -39,7 +39,24 @@ module.exports = function(knex) {
logins: 2, logins: 2,
created_at: new Date(), created_at: new Date(),
updated_at: new Date() updated_at: new Date()
}], 'id'); }], 'id').then(function() {
return knex('composite_key_test').insert([{
column_a: 1,
column_b: 1,
details: 'One, One, One',
status: 1
}, {
column_a: 1,
column_b: 2,
details: 'One, Two, Zero',
status: 0
}, {
column_a: 1,
column_b: 3,
details: 'One, Three, Zero',
status: 0
}]);
});
}); });

View File

@ -136,17 +136,19 @@ module.exports = function(knex) {
if (knex.client.dialect != 'sqlite3') { if (knex.client.dialect != 'sqlite3') {
return knex('composite_key_test') return knex('composite_key_test')
.whereIn(['column_a', 'column_b'], [[1, 1], [1, 2]]) .whereIn(['column_a', 'column_b'], [[1, 1], [1, 2]])
.logMe()
.select(); .select();
} else { } else {
return true return true;
} }
}); });
it('handles multi-column "or where in" cases', function() { it('handles multi-column "or where in" cases', function() {
if (knex.client.dialect != 'sqlite3') { if (knex.client.dialect != 'sqlite3') {
return knex('composite_key_test') return knex('composite_key_test')
.where('status', 1) .where('status', 1)
.logMe()
.whereIn(['column_a', 'column_b'], [[1, 1], [1, 2]]) .whereIn(['column_a', 'column_b'], [[1, 1], [1, 2]])
.select(); .select();
} else { } else {
@ -155,11 +157,11 @@ module.exports = function(knex) {
}); });
it('handles "where exists"', function() { it('handles "where exists"', function() {
return knex('accounts') return knex('accounts')
.whereExists(function(qb) { .whereExists(function() {
this.select('id').from('test_table_two').where({id: 1}); this.select('id').from('test_table_two').where({id: 1});
}) })
.select(); .select();

View File

@ -86,8 +86,8 @@ module.exports = {
email: 'test@example.com', email: 'test@example.com',
logins: 1, logins: 1,
about: 'Lorem ipsum Dolore labore incididunt enim.', about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: 1385400239318, created_at: 1395875717488,
updated_at: 1385400239318, updated_at: 1395875717488,
phone: null, phone: null,
details: 'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' details: 'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.'
},{ },{
@ -97,8 +97,8 @@ module.exports = {
email: 'test2@example.com', email: 'test2@example.com',
logins: 1, logins: 1,
about: 'Lorem ipsum Dolore labore incididunt enim.', about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: 1385400239319, created_at: 1395875717489,
updated_at: 1385400239319, updated_at: 1395875717489,
phone: null, phone: null,
details: 'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' details: 'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.'
},{ },{
@ -108,8 +108,8 @@ module.exports = {
email: 'test3@example.com', email: 'test3@example.com',
logins: 2, logins: 2,
about: 'Lorem ipsum Dolore labore incididunt enim.', about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: 1385400239319, created_at: 1395875717489,
updated_at: 1385400239319, updated_at: 1395875717489,
phone: null, phone: null,
details: '' details: ''
}] }]
@ -268,8 +268,8 @@ module.exports = {
email: 'test@example.com', email: 'test@example.com',
logins: 1, logins: 1,
about: 'Lorem ipsum Dolore labore incididunt enim.', about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: 1385400239318, created_at: 1395875717488,
updated_at: 1385400239318, updated_at: 1395875717488,
phone: null, phone: null,
details: 'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' details: 'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.'
},{ },{
@ -279,8 +279,8 @@ module.exports = {
email: 'test2@example.com', email: 'test2@example.com',
logins: 1, logins: 1,
about: 'Lorem ipsum Dolore labore incididunt enim.', about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: 1385400239319, created_at: 1395875717489,
updated_at: 1385400239319, updated_at: 1395875717489,
phone: null, phone: null,
details: 'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' details: 'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.'
},{ },{
@ -290,8 +290,8 @@ module.exports = {
email: 'test3@example.com', email: 'test3@example.com',
logins: 2, logins: 2,
about: 'Lorem ipsum Dolore labore incididunt enim.', about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: 1385400239319, created_at: 1395875717489,
updated_at: 1385400239319, updated_at: 1395875717489,
phone: null, phone: null,
details: '' details: ''
},{ },{
@ -301,8 +301,8 @@ module.exports = {
email: 'test4@example.com', email: 'test4@example.com',
logins: 2, logins: 2,
about: 'Lorem ipsum Dolore labore incididunt enim.', about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: 1385400239321, created_at: 1395875717490,
updated_at: 1385400239321, updated_at: 1395875717490,
phone: null, phone: null,
details: null details: null
},{ },{
@ -312,8 +312,8 @@ module.exports = {
email: 'test5@example.com', email: 'test5@example.com',
logins: 2, logins: 2,
about: 'Lorem ipsum Dolore labore incididunt enim.', about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: 1385400239321, created_at: 1395875717490,
updated_at: 1385400239321, updated_at: 1395875717490,
phone: null, phone: null,
details: null details: null
},{ },{
@ -323,8 +323,8 @@ module.exports = {
email: 'test6@example.com', email: 'test6@example.com',
logins: 2, logins: 2,
about: 'Lorem ipsum Dolore labore incididunt enim.', about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: 1385400239326, created_at: 1395875717493,
updated_at: 1385400239326, updated_at: 1395875717493,
phone: null, phone: null,
details: null details: null
}] }]
@ -519,8 +519,8 @@ module.exports = {
email: 'test@example.com', email: 'test@example.com',
logins: 1, logins: 1,
about: 'Lorem ipsum Dolore labore incididunt enim.', about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: 1385400239318, created_at: 1395875717488,
updated_at: 1385400239318, updated_at: 1395875717488,
phone: null, phone: null,
account_id: 1, account_id: 1,
details: 'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.', details: 'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.',
@ -533,8 +533,8 @@ module.exports = {
email: 'test2@example.com', email: 'test2@example.com',
logins: 1, logins: 1,
about: 'Lorem ipsum Dolore labore incididunt enim.', about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: 1385400239319, created_at: 1395875717489,
updated_at: 1385400239319, updated_at: 1395875717489,
phone: null, phone: null,
account_id: 2, account_id: 2,
details: 'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.', details: 'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.',
@ -547,8 +547,8 @@ module.exports = {
email: 'test3@example.com', email: 'test3@example.com',
logins: 2, logins: 2,
about: 'Lorem ipsum Dolore labore incididunt enim.', about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: 1385400239319, created_at: 1395875717489,
updated_at: 1385400239319, updated_at: 1395875717489,
phone: null, phone: null,
account_id: 3, account_id: 3,
details: '', details: '',
@ -561,8 +561,8 @@ module.exports = {
email: 'test4@example.com', email: 'test4@example.com',
logins: 2, logins: 2,
about: 'Lorem ipsum Dolore labore incididunt enim.', about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: 1385400239321, created_at: 1395875717490,
updated_at: 1385400239321, updated_at: 1395875717490,
phone: null, phone: null,
account_id: null, account_id: null,
details: null, details: null,
@ -575,8 +575,8 @@ module.exports = {
email: 'test5@example.com', email: 'test5@example.com',
logins: 2, logins: 2,
about: 'Lorem ipsum Dolore labore incididunt enim.', about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: 1385400239321, created_at: 1395875717490,
updated_at: 1385400239321, updated_at: 1395875717490,
phone: null, phone: null,
account_id: null, account_id: null,
details: null, details: null,
@ -589,8 +589,8 @@ module.exports = {
email: 'test6@example.com', email: 'test6@example.com',
logins: 2, logins: 2,
about: 'Lorem ipsum Dolore labore incididunt enim.', about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: 1385400239326, created_at: 1395875717493,
updated_at: 1385400239326, updated_at: 1395875717493,
phone: null, phone: null,
account_id: null, account_id: null,
details: null, details: null,

View File

@ -104,7 +104,7 @@ module.exports = {
}, },
postgresql: { postgresql: {
bindings: [], bindings: [],
sql: ['create table "composite_key_test" ("column_a" integer, "column_b" integer, "details" text, "status" smallint)','alter table "composite_key_test" add constraint composite_key_test_column_a_column_b_unique unique ("column_a", "column_b")'] sql: ['create table "composite_key_test" ("column_a" integer, "column_b" integer, "details" text, "status" smallint)','alter table "composite_key_test" add constraint composite_key_test_column_a_column_b_unique unique ("column_a", "column_b")']
}, },
sqlite3: { sqlite3: {
bindings: [], bindings: [],

View File

@ -1,4 +1,58 @@
module.exports = { module.exports = {
'handles multi-column "where in" cases': {
mysql: {
bindings: [1,1,1,2],
sql: 'select * from `composite_key_test` where (`column_a`,`column_b`) in ((?, ?),(?, ?))',
result: [{
column_a: 1,
column_b: 1,
details: 'One, One, One',
status: 1
},{
column_a: 1,
column_b: 2,
details: 'One, Two, Zero',
status: 0
}]
},
postgresql: {
bindings: [1,1,1,2],
sql: 'select * from "composite_key_test" where ("column_a","column_b") in ((?, ?),(?, ?))',
result: [{
column_a: 1,
column_b: 1,
details: 'One, One, One',
status: 1
},{
column_a: 1,
column_b: 2,
details: 'One, Two, Zero',
status: 0
}]
}
},
'handles multi-column "or where in" cases': {
mysql: {
bindings: [1,1,1,1,2],
sql: 'select * from `composite_key_test` where `status` = ? and (`column_a`,`column_b`) in ((?, ?),(?, ?))',
result: [{
column_a: 1,
column_b: 1,
details: 'One, One, One',
status: 1
}]
},
postgresql: {
bindings: [1,1,1,1,2],
sql: 'select * from "composite_key_test" where "status" = ? and ("column_a","column_b") in ((?, ?),(?, ?))',
result: [{
column_a: 1,
column_b: 1,
details: 'One, One, One',
status: 1
}]
}
},
'allows key, value': { 'allows key, value': {
mysql: { mysql: {
bindings: [1], bindings: [1],