2019-03-04 01:40:35 +01:00
/*global describe, expect, it, d*/
2014-09-01 17:18:45 +02:00
'use strict' ;
2018-10-15 22:29:53 -04:00
const uuid = require ( 'uuid' ) ;
const _ = require ( 'lodash' ) ;
2019-06-08 02:34:41 +02:00
const bluebird = require ( 'bluebird' ) ;
2013-09-11 23:36:55 -04:00
2013-09-08 15:57:32 -04:00
module . exports = function ( knex ) {
2013-09-12 13:30:47 -04:00
describe ( 'Inserts' , function ( ) {
2018-07-09 08:10:34 -04:00
it ( 'should handle simple inserts' , function ( ) {
return knex ( 'accounts' )
. insert (
{
first _name : 'Test' ,
last _name : 'User' ,
email : 'test@example.com' ,
logins : 1 ,
about : 'Lorem ipsum Dolore labore incididunt enim.' ,
created _at : d ,
updated _at : d ,
} ,
'id'
)
. testSql ( function ( tester ) {
tester (
'mysql' ,
'insert into `accounts` (`about`, `created_at`, `email`, `first_name`, `last_name`, `logins`, `updated_at`) values (?, ?, ?, ?, ?, ?, ?)' ,
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test@example.com' ,
'Test' ,
'User' ,
1 ,
d ,
] ,
[ 1 ]
) ;
tester (
'pg' ,
'insert into "accounts" ("about", "created_at", "email", "first_name", "last_name", "logins", "updated_at") values (?, ?, ?, ?, ?, ?, ?) returning "id"' ,
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test@example.com' ,
'Test' ,
'User' ,
1 ,
d ,
] ,
[ '1' ]
) ;
tester (
'pg-redshift' ,
'insert into "accounts" ("about", "created_at", "email", "first_name", "last_name", "logins", "updated_at") values (?, ?, ?, ?, ?, ?, ?)' ,
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test@example.com' ,
'Test' ,
'User' ,
1 ,
d ,
] ,
1
) ;
tester (
'sqlite3' ,
'insert into `accounts` (`about`, `created_at`, `email`, `first_name`, `last_name`, `logins`, `updated_at`) values (?, ?, ?, ?, ?, ?, ?)' ,
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test@example.com' ,
'Test' ,
'User' ,
1 ,
d ,
] ,
[ 1 ]
) ;
tester (
'oracledb' ,
'insert into "accounts" ("about", "created_at", "email", "first_name", "last_name", "logins", "updated_at") values (?, ?, ?, ?, ?, ?, ?) returning "id" into ?' ,
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test@example.com' ,
'Test' ,
'User' ,
1 ,
d ,
function ( v ) {
return v . toString ( ) === '[object ReturningHelper:id]' ;
} ,
] ,
[ '1' ]
) ;
tester (
'mssql' ,
'insert into [accounts] ([about], [created_at], [email], [first_name], [last_name], [logins], [updated_at]) output inserted.[id] values (?, ?, ?, ?, ?, ?, ?)' ,
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test@example.com' ,
'Test' ,
'User' ,
1 ,
d ,
] ,
[ '1' ]
) ;
} ) ;
2013-09-11 23:36:55 -04:00
} ) ;
it ( 'should handle multi inserts' , function ( ) {
return knex ( 'accounts' )
2018-07-09 08:10:34 -04:00
. insert (
[
{
first _name : 'Test' ,
last _name : 'User' ,
email : 'test2@example.com' ,
logins : 1 ,
about : 'Lorem ipsum Dolore labore incididunt enim.' ,
created _at : d ,
updated _at : d ,
} ,
{
first _name : 'Test' ,
last _name : 'User' ,
email : 'test3@example.com' ,
about : 'Lorem ipsum Dolore labore incididunt enim.' ,
logins : 2 ,
created _at : d ,
updated _at : d ,
} ,
] ,
'id'
)
. testSql ( function ( tester ) {
2013-12-27 14:44:21 -05:00
tester (
'mysql' ,
'insert into `accounts` (`about`, `created_at`, `email`, `first_name`, `last_name`, `logins`, `updated_at`) values (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?)' ,
2018-07-09 08:10:34 -04:00
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test2@example.com' ,
'Test' ,
'User' ,
1 ,
d ,
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test3@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
] ,
2013-12-27 14:44:21 -05:00
[ 2 ]
) ;
tester (
2018-06-29 10:47:06 +03:00
'pg' ,
2013-12-27 14:44:21 -05:00
'insert into "accounts" ("about", "created_at", "email", "first_name", "last_name", "logins", "updated_at") values (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?) returning "id"' ,
2018-07-09 08:10:34 -04:00
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test2@example.com' ,
'Test' ,
'User' ,
1 ,
d ,
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test3@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
] ,
[ '2' , '3' ]
2013-12-27 14:44:21 -05:00
) ;
2018-02-03 08:33:02 -05:00
tester (
'pg-redshift' ,
'insert into "accounts" ("about", "created_at", "email", "first_name", "last_name", "logins", "updated_at") values (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?)' ,
2018-07-09 08:10:34 -04:00
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test2@example.com' ,
'Test' ,
'User' ,
1 ,
d ,
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test3@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
] ,
2018-02-03 08:33:02 -05:00
2
) ;
2013-12-27 14:44:21 -05:00
tester (
'sqlite3' ,
2017-05-28 22:48:18 +02:00
'insert into `accounts` (`about`, `created_at`, `email`, `first_name`, `last_name`, `logins`, `updated_at`) select ? as `about`, ? as `created_at`, ? as `email`, ? as `first_name`, ? as `last_name`, ? as `logins`, ? as `updated_at` union all select ? as `about`, ? as `created_at`, ? as `email`, ? as `first_name`, ? as `last_name`, ? as `logins`, ? as `updated_at`' ,
2018-07-09 08:10:34 -04:00
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test2@example.com' ,
'Test' ,
'User' ,
1 ,
d ,
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test3@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
] ,
2013-12-27 14:44:21 -05:00
[ 3 ]
) ;
2014-08-11 12:25:39 +02:00
tester (
2018-07-08 14:10:51 +03:00
'oracledb' ,
2018-07-09 08:10:34 -04:00
'begin execute immediate \'insert into "accounts" ("about", "created_at", "email", "first_name", "last_name", "logins", "updated_at") values (:1, :2, :3, :4, :5, :6, :7) returning "id" into :8\' using ?, ?, ?, ?, ?, ?, ?, out ?; execute immediate \'insert into "accounts" ("about", "created_at", "email", "first_name", "last_name", "logins", "updated_at") values (:1, :2, :3, :4, :5, :6, :7) returning "id" into :8\' using ?, ?, ?, ?, ?, ?, ?, out ?;end;' ,
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test2@example.com' ,
'Test' ,
'User' ,
1 ,
d ,
function ( v ) {
return v . toString ( ) === '[object ReturningHelper:id]' ;
} ,
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test3@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
function ( v ) {
return v . toString ( ) === '[object ReturningHelper:id]' ;
} ,
] ,
2018-07-08 14:10:51 +03:00
[ '2' , '3' ]
2014-08-11 12:25:39 +02:00
) ;
2015-12-09 17:53:53 -06:00
tester (
'mssql' ,
'insert into [accounts] ([about], [created_at], [email], [first_name], [last_name], [logins], [updated_at]) output inserted.[id] values (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?)' ,
2018-07-09 08:10:34 -04:00
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test2@example.com' ,
'Test' ,
'User' ,
1 ,
d ,
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test3@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
] ,
2015-12-09 17:53:53 -06:00
[ '2' , '3' ]
) ;
2013-12-27 14:44:21 -05:00
} ) ;
2013-09-11 23:36:55 -04:00
} ) ;
2015-04-22 10:34:14 -04:00
it ( 'should allow for using the `asCallback` interface' , function ( ok ) {
2018-07-09 08:10:34 -04:00
knex ( 'test_table_two' )
. insert (
2018-02-03 08:33:02 -05:00
[
2018-07-09 08:10:34 -04:00
{
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.' ,
status : 0 ,
} ,
{
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.' ,
status : 1 ,
} ,
{
account _id : 3 ,
details : '' ,
status : 1 ,
} ,
2018-02-03 08:33:02 -05:00
] ,
2018-07-09 08:10:34 -04:00
'id'
)
. testSql ( function ( tester ) {
tester (
'oracledb' ,
'begin execute immediate \'insert into "test_table_two" ("account_id", "details", "status") values (:1, :2, :3) returning "id" into :4\' using ?, ?, ?, out ?; execute immediate \'insert into "test_table_two" ("account_id", "details", "status") values (:1, :2, :3) returning "id" into :4\' using ?, ?, ?, out ?; execute immediate \'insert into "test_table_two" ("account_id", "details", "status") values (:1, :2, :3) returning "id" into :4\' using ?, ?, ?, out ?;end;' ,
[
1 ,
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
0 ,
function ( v ) {
return v . toString ( ) === '[object ReturningHelper:id]' ;
} ,
2 ,
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
1 ,
function ( v ) {
return v . toString ( ) === '[object ReturningHelper:id]' ;
} ,
3 ,
'' ,
1 ,
function ( v ) {
return v . toString ( ) === '[object ReturningHelper:id]' ;
} ,
] ,
[ '1' , '2' , '3' ]
) ;
} )
. asCallback ( function ( err ) {
if ( err ) return ok ( err ) ;
ok ( ) ;
} ) ;
2013-09-11 23:36:55 -04:00
} ) ;
it ( 'should take hashes passed into insert and keep them in the correct order' , function ( ) {
2018-07-09 08:10:34 -04:00
return knex ( 'accounts' )
. insert (
2014-08-21 23:39:12 +02:00
[
2018-07-09 08:10:34 -04:00
{
first _name : 'Test' ,
last _name : 'User' ,
email : 'test4@example.com' ,
about : 'Lorem ipsum Dolore labore incididunt enim.' ,
logins : 2 ,
created _at : d ,
updated _at : d ,
} ,
{
first _name : 'Test' ,
about : 'Lorem ipsum Dolore labore incididunt enim.' ,
logins : 2 ,
created _at : d ,
updated _at : d ,
last _name : 'User' ,
email : 'test5@example.com' ,
} ,
2014-08-21 23:39:12 +02:00
] ,
2018-07-09 08:10:34 -04:00
'id'
)
. testSql ( function ( tester ) {
tester (
'mysql' ,
'insert into `accounts` (`about`, `created_at`, `email`, `first_name`, `last_name`, `logins`, `updated_at`) values (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?)' ,
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test4@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test5@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
] ,
[ 4 ]
) ;
tester (
'pg' ,
'insert into "accounts" ("about", "created_at", "email", "first_name", "last_name", "logins", "updated_at") values (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?) returning "id"' ,
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test4@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test5@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
] ,
[ '4' , '5' ]
) ;
tester (
'pg-redshift' ,
'insert into "accounts" ("about", "created_at", "email", "first_name", "last_name", "logins", "updated_at") values (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?)' ,
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test4@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test5@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
] ,
2
) ;
tester (
'sqlite3' ,
'insert into `accounts` (`about`, `created_at`, `email`, `first_name`, `last_name`, `logins`, `updated_at`) select ? as `about`, ? as `created_at`, ? as `email`, ? as `first_name`, ? as `last_name`, ? as `logins`, ? as `updated_at` union all select ? as `about`, ? as `created_at`, ? as `email`, ? as `first_name`, ? as `last_name`, ? as `logins`, ? as `updated_at`' ,
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test4@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test5@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
] ,
[ 5 ]
) ;
tester (
'oracledb' ,
'begin execute immediate \'insert into "accounts" ("about", "created_at", "email", "first_name", "last_name", "logins", "updated_at") values (:1, :2, :3, :4, :5, :6, :7) returning "id" into :8\' using ?, ?, ?, ?, ?, ?, ?, out ?; execute immediate \'insert into "accounts" ("about", "created_at", "email", "first_name", "last_name", "logins", "updated_at") values (:1, :2, :3, :4, :5, :6, :7) returning "id" into :8\' using ?, ?, ?, ?, ?, ?, ?, out ?;end;' ,
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test4@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
function ( v ) {
return v . toString ( ) === '[object ReturningHelper:id]' ;
} ,
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test5@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
function ( v ) {
return v . toString ( ) === '[object ReturningHelper:id]' ;
} ,
] ,
[ '4' , '5' ]
) ;
tester (
'mssql' ,
'insert into [accounts] ([about], [created_at], [email], [first_name], [last_name], [logins], [updated_at]) output inserted.[id] values (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?)' ,
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test4@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test5@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
] ,
[ '4' , '5' ]
) ;
} ) ;
2013-09-11 23:36:55 -04:00
} ) ;
2013-12-27 14:44:21 -05:00
it ( 'will fail when multiple inserts are made into a unique column' , function ( ) {
2018-07-09 08:10:34 -04:00
if ( /redshift/i . test ( knex . client . driverName ) ) {
return ;
}
2013-11-25 12:26:28 -05:00
return knex ( 'accounts' )
2013-09-11 23:36:55 -04:00
. where ( 'id' , '>' , 1 )
. orWhere ( 'x' , 2 )
2018-07-09 08:10:34 -04:00
. insert (
{
first _name : 'Test' ,
last _name : 'User' ,
email : 'test5@example.com' ,
about : 'Lorem ipsum Dolore labore incididunt enim.' ,
logins : 2 ,
created _at : d ,
updated _at : d ,
} ,
'id'
)
2013-12-27 14:44:21 -05:00
. testSql ( function ( tester ) {
tester (
'mysql' ,
'insert into `accounts` (`about`, `created_at`, `email`, `first_name`, `last_name`, `logins`, `updated_at`) values (?, ?, ?, ?, ?, ?, ?)' ,
2018-07-09 08:10:34 -04:00
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test5@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
]
2013-12-27 14:44:21 -05:00
) ;
tester (
2018-06-29 10:47:06 +03:00
'pg' ,
2013-12-27 14:44:21 -05:00
'insert into "accounts" ("about", "created_at", "email", "first_name", "last_name", "logins", "updated_at") values (?, ?, ?, ?, ?, ?, ?) returning "id"' ,
2018-07-09 08:10:34 -04:00
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test5@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
]
2013-12-27 14:44:21 -05:00
) ;
tester (
'sqlite3' ,
2017-05-28 22:48:18 +02:00
'insert into `accounts` (`about`, `created_at`, `email`, `first_name`, `last_name`, `logins`, `updated_at`) values (?, ?, ?, ?, ?, ?, ?)' ,
2018-07-09 08:10:34 -04:00
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test5@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
]
2013-12-27 14:44:21 -05:00
) ;
2014-08-21 23:39:12 +02:00
tester (
2018-07-08 14:10:51 +03:00
'oracledb' ,
2018-07-09 08:10:34 -04:00
'insert into "accounts" ("about", "created_at", "email", "first_name", "last_name", "logins", "updated_at") values (?, ?, ?, ?, ?, ?, ?) returning "id" into ?' ,
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test5@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
function ( v ) {
return v . toString ( ) === '[object ReturningHelper:id]' ;
} ,
]
2014-08-21 23:39:12 +02:00
) ;
2015-12-09 17:53:53 -06:00
tester (
'mssql' ,
'insert into [accounts] ([about], [created_at], [email], [first_name], [last_name], [logins], [updated_at]) output inserted.[id] values (?, ?, ?, ?, ?, ?, ?)' ,
2018-07-09 08:10:34 -04:00
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test5@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
]
2015-12-09 17:53:53 -06:00
) ;
2013-12-27 14:44:21 -05:00
} )
2018-07-09 08:10:34 -04:00
. then (
function ( ) {
throw new Error (
'There should be a fail when multi-insert are made in unique col.'
) ;
} ,
function ( ) { }
) ;
2013-09-11 23:36:55 -04:00
} ) ;
it ( 'should drop any where clause bindings' , function ( ) {
return knex ( 'accounts' )
. where ( 'id' , '>' , 1 )
. orWhere ( 'x' , 2 )
2018-07-09 08:10:34 -04:00
. insert (
{
first _name : 'Test' ,
last _name : 'User' ,
email : 'test6@example.com' ,
about : 'Lorem ipsum Dolore labore incididunt enim.' ,
logins : 2 ,
created _at : d ,
updated _at : d ,
} ,
'id'
)
. testSql ( function ( tester ) {
2013-12-27 14:44:21 -05:00
tester (
'mysql' ,
'insert into `accounts` (`about`, `created_at`, `email`, `first_name`, `last_name`, `logins`, `updated_at`) values (?, ?, ?, ?, ?, ?, ?)' ,
2018-07-09 08:10:34 -04:00
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test6@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
] ,
2013-12-27 14:44:21 -05:00
[ 7 ]
) ;
tester (
2018-06-29 10:47:06 +03:00
'pg' ,
2013-12-27 14:44:21 -05:00
'insert into "accounts" ("about", "created_at", "email", "first_name", "last_name", "logins", "updated_at") values (?, ?, ?, ?, ?, ?, ?) returning "id"' ,
2018-07-09 08:10:34 -04:00
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test6@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
] ,
2013-12-27 14:44:21 -05:00
[ '7' ]
) ;
2018-02-03 08:33:02 -05:00
tester (
'pg-redshift' ,
'insert into "accounts" ("about", "created_at", "email", "first_name", "last_name", "logins", "updated_at") values (?, ?, ?, ?, ?, ?, ?)' ,
2018-07-09 08:10:34 -04:00
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test6@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
] ,
2018-02-03 08:33:02 -05:00
1
) ;
2013-12-27 14:44:21 -05:00
tester (
'sqlite3' ,
2017-05-28 22:48:18 +02:00
'insert into `accounts` (`about`, `created_at`, `email`, `first_name`, `last_name`, `logins`, `updated_at`) values (?, ?, ?, ?, ?, ?, ?)' ,
2018-07-09 08:10:34 -04:00
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test6@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
] ,
2013-12-27 14:44:21 -05:00
[ 6 ]
) ;
2014-08-21 23:39:12 +02:00
tester (
2018-07-08 14:10:51 +03:00
'oracledb' ,
2018-07-09 08:10:34 -04:00
'insert into "accounts" ("about", "created_at", "email", "first_name", "last_name", "logins", "updated_at") values (?, ?, ?, ?, ?, ?, ?) returning "id" into ?' ,
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test6@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
function ( v ) {
return v . toString ( ) === '[object ReturningHelper:id]' ;
} ,
] ,
2018-07-08 14:10:51 +03:00
[ '7' ]
2014-08-21 23:39:12 +02:00
) ;
2015-12-09 17:53:53 -06:00
tester (
'mssql' ,
'insert into [accounts] ([about], [created_at], [email], [first_name], [last_name], [logins], [updated_at]) output inserted.[id] values (?, ?, ?, ?, ?, ?, ?)' ,
2018-07-09 08:10:34 -04:00
[
'Lorem ipsum Dolore labore incididunt enim.' ,
d ,
'test6@example.com' ,
'Test' ,
'User' ,
2 ,
d ,
] ,
2015-12-09 17:53:53 -06:00
[ '7' ]
) ;
2013-12-27 14:44:21 -05:00
} ) ;
2013-09-11 23:36:55 -04:00
} ) ;
2013-11-25 12:26:28 -05:00
it ( 'should not allow inserting invalid values into enum fields' , function ( ) {
return knex ( 'datatype_test' )
2018-07-09 08:10:34 -04:00
. insert ( { enum _value : 'd' } )
2013-12-27 14:44:21 -05:00
. testSql ( function ( tester ) {
tester (
'mysql' ,
'insert into `datatype_test` (`enum_value`) values (?)' ,
[ 'd' ]
) ;
tester (
2018-06-29 10:47:06 +03:00
'pg' ,
2013-12-27 14:44:21 -05:00
'insert into "datatype_test" ("enum_value") values (?)' ,
[ 'd' ]
) ;
2018-02-03 08:33:02 -05:00
tester (
'pg-redshift' ,
'insert into "datatype_test" ("enum_value") values (?)' ,
[ 'd' ]
) ;
2013-12-27 14:44:21 -05:00
tester (
'sqlite3' ,
2017-05-28 22:48:18 +02:00
'insert into `datatype_test` (`enum_value`) values (?)' ,
2013-12-27 14:44:21 -05:00
[ 'd' ] ,
[ 1 ]
) ;
2014-08-21 23:39:12 +02:00
tester (
2018-07-08 14:10:51 +03:00
'oracledb' ,
2014-08-21 23:39:12 +02:00
'insert into "datatype_test" ("enum_value") values (?)' ,
[ 'd' ]
) ;
2015-12-09 17:53:53 -06:00
tester (
'mssql' ,
'insert into [datatype_test] ([enum_value]) values (?)' ,
[ 'd' ]
) ;
2013-12-27 14:44:21 -05:00
} )
2018-07-09 08:10:34 -04:00
. then (
function ( ) {
// No errors happen in sqlite3, which doesn't have native support
// for the enum type.
if ( knex . client . driverName !== 'sqlite3' ) {
throw new Error (
'There should be an error for invalid enum inserts'
) ;
}
} ,
function ( ) { }
) ;
2013-09-11 23:36:55 -04:00
} ) ;
2013-11-25 12:26:28 -05:00
it ( 'should not allow invalid uuids in postgresql' , function ( ) {
return knex ( 'datatype_test' )
2013-09-11 23:36:55 -04:00
. insert ( {
enum _value : 'c' ,
2018-07-09 08:10:34 -04:00
uuid : uuid . v4 ( ) ,
} )
. then ( function ( ) {
return knex ( 'datatype_test' ) . insert ( {
enum _value : 'c' ,
uuid : 'test' ,
} ) ;
} )
. then (
function ( ) {
// No errors happen in sqlite3 or mysql, which dont have native support
// for the uuid type.
if (
knex . client . driverName === 'pg' ||
knex . client . driverName === 'mssql'
) {
throw new Error (
'There should be an error in postgresql for uuids'
) ;
}
} ,
function ( ) { }
) ;
2013-09-11 23:36:55 -04:00
} ) ;
it ( 'should not mutate the array passed in' , function ( ) {
2018-10-15 22:29:53 -04:00
const a = { enum _value : 'a' , uuid : uuid . v4 ( ) } ;
const b = { enum _value : 'c' , uuid : uuid . v4 ( ) } ;
const x = [ a , b ] ;
2013-09-11 23:36:55 -04:00
return knex ( 'datatype_test' )
. insert ( x )
. then ( function ( ) {
expect ( x ) . to . eql ( [ a , b ] ) ;
} ) ;
} ) ;
it ( 'should handle empty inserts' , function ( ) {
2013-12-27 14:44:21 -05:00
return knex . schema
. createTable ( 'test_default_table' , function ( qb ) {
qb . increments ( ) . primary ( ) ;
qb . string ( 'string' ) . defaultTo ( 'hello' ) ;
qb . tinyint ( 'tinyint' ) . defaultTo ( 0 ) ;
qb . text ( 'text' ) . nullable ( ) ;
2018-07-09 08:10:34 -04:00
} )
. then ( function ( ) {
return knex ( 'test_default_table' )
. insert ( { } , 'id' )
. testSql ( function ( tester ) {
tester (
'mysql' ,
'insert into `test_default_table` () values ()' ,
[ ] ,
[ 1 ]
) ;
tester (
'pg' ,
'insert into "test_default_table" default values returning "id"' ,
[ ] ,
[ 1 ]
) ;
tester (
'pg-redshift' ,
'insert into "test_default_table" default values' ,
[ ] ,
1
) ;
tester (
'sqlite3' ,
'insert into `test_default_table` default values' ,
[ ] ,
[ 1 ]
) ;
tester (
'oracledb' ,
'insert into "test_default_table" ("id") values (default) returning "id" into ?' ,
[
function ( v ) {
return v . toString ( ) === '[object ReturningHelper:id]' ;
} ,
] ,
[ '1' ]
) ;
tester (
'mssql' ,
'insert into [test_default_table] output inserted.[id] default values' ,
[ ] ,
[ 1 ]
) ;
} ) ;
2013-12-27 14:44:21 -05:00
} ) ;
2013-12-10 13:33:49 -05:00
} ) ;
2013-09-12 13:30:47 -04:00
2014-09-08 16:02:46 +02:00
it ( 'should handle empty arrays inserts' , function ( ) {
return knex . schema
. createTable ( 'test_default_table2' , function ( qb ) {
qb . increments ( ) . primary ( ) ;
qb . string ( 'string' ) . defaultTo ( 'hello' ) ;
qb . tinyint ( 'tinyint' ) . defaultTo ( 0 ) ;
qb . text ( 'text' ) . nullable ( ) ;
2018-07-09 08:10:34 -04:00
} )
. then ( function ( ) {
return knex ( 'test_default_table2' )
. insert ( [ { } ] , 'id' )
. testSql ( function ( tester ) {
tester (
'mysql' ,
'insert into `test_default_table2` () values ()' ,
[ ] ,
[ 1 ]
) ;
tester (
'pg' ,
'insert into "test_default_table2" default values returning "id"' ,
[ ] ,
[ 1 ]
) ;
tester (
'pg-redshift' ,
'insert into "test_default_table2" default values' ,
[ ] ,
1
) ;
tester (
'sqlite3' ,
'insert into `test_default_table2` default values' ,
[ ] ,
[ 1 ]
) ;
tester (
'oracledb' ,
'insert into "test_default_table2" ("id") values (default) returning "id" into ?' ,
[
function ( v ) {
return v . toString ( ) === '[object ReturningHelper:id]' ;
} ,
] ,
[ '1' ]
) ;
tester (
'mssql' ,
'insert into [test_default_table2] output inserted.[id] default values' ,
[ ] ,
[ 1 ]
) ;
} ) ;
2014-09-08 16:02:46 +02:00
} ) ;
} ) ;
2015-03-24 17:48:14 -07:00
it ( 'should take an array of columns to return in oracle or postgres' , function ( ) {
2018-10-15 22:29:53 -04:00
const insertData = {
2013-12-10 13:33:49 -05:00
account _id : 10 ,
2018-07-09 08:10:34 -04:00
details :
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
status : 0 ,
2013-12-10 13:33:49 -05:00
} ;
2018-07-09 08:10:34 -04:00
return knex ( 'test_table_two' )
. insert ( insertData , [ 'account_id' , 'details' ] )
. testSql ( function ( tester ) {
tester (
'mysql' ,
'insert into `test_table_two` (`account_id`, `details`, `status`) values (?, ?, ?)' ,
[
10 ,
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
0 ,
] ,
[ 4 ]
) ;
tester (
'pg' ,
'insert into "test_table_two" ("account_id", "details", "status") values (?, ?, ?) returning "account_id", "details"' ,
[
10 ,
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
0 ,
] ,
[
{
account _id : 10 ,
details :
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
} ,
]
) ;
tester (
'pg-redshift' ,
'insert into "test_table_two" ("account_id", "details", "status") values (?, ?, ?)' ,
[
10 ,
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
0 ,
] ,
1
) ;
tester (
'sqlite3' ,
'insert into `test_table_two` (`account_id`, `details`, `status`) values (?, ?, ?)' ,
[
10 ,
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
0 ,
] ,
[ 4 ]
) ;
tester (
'oracledb' ,
` insert into "test_table_two" ("account_id", "details", "status") values (?, ?, ?) returning "account_id","details" into ?,? ` ,
[
10 ,
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
0 ,
function ( v ) {
return v . toString ( ) === '[object ReturningHelper:account_id]' ;
} ,
function ( v ) {
return v . toString ( ) === '[object ReturningHelper:details]' ;
} ,
] ,
[
{
account _id : '10' ,
details :
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
} ,
]
) ;
tester (
'mssql' ,
'insert into [test_table_two] ([account_id], [details], [status]) output inserted.[account_id], inserted.[details] values (?, ?, ?)' ,
[
10 ,
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
0 ,
] ,
[
{
account _id : 10 ,
details :
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
} ,
]
) ;
} )
. then ( function ( rows ) {
if ( /redshift/ . test ( knex . client . driverName ) ) {
return expect ( rows ) . to . equal ( 1 ) ;
}
expect ( rows . length ) . to . equal ( 1 ) ;
if ( knex . client . driverName === 'pg' ) {
expect ( _ . keys ( rows [ 0 ] ) . length ) . to . equal ( 2 ) ;
expect ( rows [ 0 ] . account _id ) . to . equal ( insertData . account _id ) ;
expect ( rows [ 0 ] . details ) . to . equal ( insertData . details ) ;
}
} ) ;
2013-12-10 13:33:49 -05:00
} ) ;
2015-03-24 17:48:14 -07:00
it ( 'should allow a * for returning in postgres and oracle' , function ( ) {
2018-07-09 08:10:34 -04:00
if ( /redshift/i . test ( knex . client . driverName ) ) {
return ;
}
2018-10-15 22:29:53 -04:00
const insertData = {
2013-12-10 13:33:49 -05:00
account _id : 10 ,
2018-07-09 08:10:34 -04:00
details :
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
status : 0 ,
2013-12-10 13:33:49 -05:00
} ;
2014-08-13 21:37:22 +02:00
2018-10-15 22:29:53 -04:00
const returningColumn = '*' ;
2018-07-09 08:10:34 -04:00
return knex ( 'test_table_two' )
. insert ( insertData , returningColumn )
. testSql ( function ( tester ) {
tester (
'pg' ,
'insert into "test_table_two" ("account_id", "details", "status") values (?, ?, ?) returning *' ,
[
10 ,
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
0 ,
] ,
[
{
id : 5 ,
account _id : 10 ,
details :
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
status : 0 ,
json _data : null ,
} ,
]
) ;
tester (
'oracledb' ,
'insert into "test_table_two" ("account_id", "details", "status") values (?, ?, ?) returning "ROWID" into ?' ,
[
10 ,
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
0 ,
function ( v ) {
return v . toString ( ) === '[object ReturningHelper:ROWID]' ;
} ,
] ,
[
{
id : 5 ,
account _id : 10 ,
details :
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
status : 0 ,
json _data : null ,
} ,
]
) ;
tester (
'mssql' ,
'insert into [test_table_two] ([account_id], [details], [status]) output inserted.* values (?, ?, ?)' ,
[
10 ,
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
0 ,
] ,
[
{
id : 5 ,
account _id : 10 ,
details :
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.' ,
status : 0 ,
json _data : null ,
} ,
]
) ;
} )
. then ( function ( rows ) {
expect ( rows . length ) . to . equal ( 1 ) ;
if ( knex . client . driverName === 'pg' ) {
expect ( _ . keys ( rows [ 0 ] ) . length ) . to . equal ( 5 ) ;
expect ( rows [ 0 ] . account _id ) . to . equal ( insertData . account _id ) ;
expect ( rows [ 0 ] . details ) . to . equal ( insertData . details ) ;
expect ( rows [ 0 ] . status ) . to . equal ( insertData . status ) ;
expect ( rows [ 0 ] . json _data ) . to . equal ( null ) ;
}
} ) ;
2013-09-11 23:36:55 -04:00
} ) ;
2019-05-13 12:21:36 +03:00
describe ( 'batchInsert (TODO: fix random oracle fail)' , function ( ) {
if ( knex . client . driverName == 'oracledb' ) {
return ;
}
2018-10-15 22:29:53 -04:00
const driverName = knex . client . driverName ;
const fiftyLengthString =
2018-07-09 08:10:34 -04:00
'rO8F8YrFS6uoivuRiVnwrO8F8YrFS6uoivuRiVnwuoivuRiVnw' ;
2018-10-15 22:29:53 -04:00
const items = [ ] ;
const amountOfItems = 100 ;
const amountOfColumns = 30 ;
for ( let i = 0 ; i < amountOfItems ; i ++ ) {
const item = { } ;
for ( let x = 0 ; x < amountOfColumns ; x ++ ) {
2016-02-04 17:26:16 +01:00
item [ 'Col' + x ] = fiftyLengthString ;
}
items . push ( item ) ;
}
2016-05-09 19:01:00 +02:00
beforeEach ( function ( ) {
2018-07-09 08:10:34 -04:00
return knex . schema . dropTableIfExists ( 'BatchInsert' ) . then ( function ( ) {
return knex . schema . createTable ( 'BatchInsert' , function ( table ) {
2018-10-15 22:29:53 -04:00
for ( let i = 0 ; i < amountOfColumns ; i ++ ) {
2018-07-09 08:10:34 -04:00
table . string ( 'Col' + i , 50 ) ;
}
2016-05-09 19:01:00 +02:00
} ) ;
2018-07-09 08:10:34 -04:00
} ) ;
2016-05-09 19:01:00 +02:00
} ) ;
it ( '#757 - knex.batchInsert(tableName, bulk, chunkSize)' , function ( ) {
2018-02-03 08:33:02 -05:00
this . timeout ( 30000 ) ;
2018-07-09 08:10:34 -04:00
return knex
. batchInsert ( 'BatchInsert' , items , 30 )
2016-05-09 19:01:00 +02:00
. returning ( [ 'Col1' , 'Col2' ] )
2018-07-09 08:10:34 -04:00
. then ( function ( result ) {
2016-05-11 17:31:33 +02:00
//Returning only supported by some dialects.
2018-07-09 08:10:34 -04:00
if ( [ 'pg' , 'oracledb' ] . indexOf ( driverName ) !== - 1 ) {
2016-05-11 17:31:33 +02:00
result . forEach ( function ( item ) {
expect ( item . Col1 ) . to . equal ( fiftyLengthString ) ;
expect ( item . Col2 ) . to . equal ( fiftyLengthString ) ;
} ) ;
}
2016-02-04 18:17:32 +01:00
return knex ( 'BatchInsert' ) . select ( ) ;
2016-02-02 21:19:36 +01:00
} )
2018-07-09 08:10:34 -04:00
. then ( function ( result ) {
2018-10-15 22:29:53 -04:00
const count = result . length ;
2016-02-04 17:26:16 +01:00
expect ( count ) . to . equal ( amountOfItems ) ;
2016-05-09 19:01:00 +02:00
} ) ;
} ) ;
2016-02-02 21:19:36 +01:00
2017-03-22 21:44:36 +01:00
it ( '#1880 - Duplicate keys in batchInsert should not throw unhandled exception' , function ( ) {
2018-07-09 08:10:34 -04:00
if ( /redshift/i . test ( knex . client . driverName ) ) {
return ;
}
2019-06-08 02:34:41 +02:00
return new bluebird ( function ( resolve , reject ) {
2018-07-09 08:10:34 -04:00
return knex . schema
. dropTableIfExists ( 'batchInsertDuplicateKey' )
2017-03-22 21:44:36 +01:00
. then ( function ( ) {
2018-07-09 08:10:34 -04:00
return knex . schema . createTable (
'batchInsertDuplicateKey' ,
function ( table ) {
table . string ( 'col' ) ;
table . primary ( 'col' ) ;
}
) ;
2017-03-22 21:44:36 +01:00
} )
2018-07-09 08:10:34 -04:00
. then ( function ( ) {
2018-10-15 22:29:53 -04:00
const rows = [ { col : 'a' } , { col : 'a' } ] ;
2018-07-09 08:10:34 -04:00
return knex . batchInsert (
'batchInsertDuplicateKey' ,
rows ,
rows . length
) ;
2017-03-22 21:44:36 +01:00
} )
2017-03-26 17:43:17 +02:00
. then ( function ( ) {
2018-07-09 08:10:34 -04:00
return reject ( new Error ( 'Should not reach this point' ) ) ;
2017-03-26 17:43:17 +02:00
} )
2018-07-09 08:10:34 -04:00
. catch ( function ( error ) {
2017-03-24 16:14:25 +01:00
//Should reach this point before timeout of 10s
2018-07-09 08:10:34 -04:00
expect ( error . message . toLowerCase ( ) ) . to . include (
'batchinsertduplicatekey'
) ;
2017-03-22 21:44:36 +01:00
resolve ( error ) ;
} ) ;
2017-03-24 16:14:25 +01:00
} ) . timeout ( 10000 ) ;
2017-03-22 21:44:36 +01:00
} ) ;
2016-05-09 19:01:00 +02:00
it ( 'knex.batchInsert with specified transaction' , function ( ) {
return knex . transaction ( function ( tr ) {
2018-07-09 08:10:34 -04:00
knex
. batchInsert ( 'BatchInsert' , items , 30 )
. returning ( [ 'Col1' , 'Col2' ] )
. transacting ( tr )
. then ( tr . commit )
. catch ( tr . rollback ) ;
} ) ;
2016-05-09 19:01:00 +02:00
} ) ;
2016-05-16 22:10:35 +01:00
it ( 'transaction.batchInsert using specified transaction' , function ( ) {
return knex . transaction ( function ( tr ) {
2018-07-09 08:10:34 -04:00
return tr
. batchInsert ( 'BatchInsert' , items , 30 )
. returning ( [ 'Col1' , 'Col2' ] ) ;
} ) ;
2016-05-16 22:10:35 +01:00
} ) ;
2016-05-09 19:01:00 +02:00
} ) ;
2013-09-11 23:36:55 -04:00
2016-05-12 09:28:38 +03:00
it ( 'should validate batchInsert batchSize parameter' , function ( ) {
2017-03-22 21:44:36 +01:00
//Should not throw, batchSize default
2018-07-09 08:10:34 -04:00
return knex
. batchInsert ( 'test' , [ ] )
. then ( function ( ) {
//Should throw, null not valid
return knex . batchInsert ( 'test' , [ ] , null ) ;
} )
. catch ( function ( error ) {
expect ( error . message ) . to . equal ( 'Invalid chunkSize: null' ) ;
2017-03-22 21:44:36 +01:00
2018-07-09 08:10:34 -04:00
//Should throw, 0 is not a valid chunkSize
return knex . batchInsert ( 'test' , [ ] , 0 ) ;
} )
. catch ( function ( error ) {
expect ( error . message ) . to . equal ( 'Invalid chunkSize: 0' ) ;
2017-03-22 21:44:36 +01:00
2018-07-09 08:10:34 -04:00
//Also faulty
return knex . batchInsert ( 'test' , [ ] , 'still no good' ) ;
} )
. catch ( function ( error ) {
expect ( error . message ) . to . equal ( 'Invalid chunkSize: still no good' ) ;
2017-03-22 21:44:36 +01:00
2018-07-09 08:10:34 -04:00
return true ;
} ) ;
2016-05-12 09:28:38 +03:00
} ) ;
2016-02-11 11:36:15 +02:00
2016-05-12 09:28:38 +03:00
it ( 'should replace undefined keys in multi insert with DEFAULT' , function ( ) {
2018-07-08 14:10:51 +03:00
if ( knex . client . driverName === 'sqlite3' ) {
2016-05-12 09:28:38 +03:00
return true ;
}
return knex ( 'accounts' )
2018-07-09 08:10:34 -04:00
. insert (
[
{
last _name : 'First Item' ,
email : 'single-test1@example.com' ,
about : 'Lorem ipsum Dolore labore incididunt enim.' ,
created _at : new Date ( ) ,
updated _at : new Date ( ) ,
} ,
{
last _name : 'Second Item' ,
email : 'double-test1@example.com' ,
logins : 2 ,
created _at : new Date ( ) ,
updated _at : new Date ( ) ,
} ,
] ,
'*'
)
. then ( function ( ) {
return knex ( 'accounts' )
. whereIn ( 'email' , [
'single-test1@example.com' ,
'double-test1@example.com' ,
] )
. orderBy ( 'email' , 'desc' ) ;
2016-05-12 09:28:38 +03:00
} )
2018-07-09 08:10:34 -04:00
. then ( function ( results ) {
2016-05-12 09:28:38 +03:00
expect ( results [ 0 ] . logins ) . to . equal ( 1 ) ;
expect ( results [ 1 ] . about ) . to . equal ( null ) ;
// cleanup to prevent needs for too much changes to other tests
2018-07-09 08:10:34 -04:00
return knex ( 'accounts' )
. delete ( )
. whereIn (
'id' ,
results . map ( function ( row ) {
return row . id ;
} )
) ;
2016-05-12 09:28:38 +03:00
} ) ;
} ) ;
2016-05-19 18:50:18 +03:00
it ( '#1423 should replace undefined keys in single insert with DEFAULT also in transacting query' , function ( ) {
2018-07-08 14:10:51 +03:00
if ( knex . client . driverName === 'sqlite3' ) {
2016-05-19 18:50:18 +03:00
return true ;
}
return knex . transaction ( function ( trx ) {
return trx ( 'accounts' )
. insert ( {
last _name : 'First Item' ,
2018-07-09 08:10:34 -04:00
email : 'findme@example.com' ,
2016-05-19 18:50:18 +03:00
logins : undefined ,
about : 'Lorem ipsum Dolore labore incididunt enim.' ,
created _at : new Date ( ) ,
2018-07-09 08:10:34 -04:00
updated _at : new Date ( ) ,
2016-05-19 18:50:18 +03:00
} )
2018-07-09 08:10:34 -04:00
. then ( function ( results ) {
2016-05-19 18:50:18 +03:00
return trx ( 'accounts' ) . where ( 'email' , 'findme@example.com' ) ;
} )
2018-07-09 08:10:34 -04:00
. then ( function ( results ) {
2016-05-19 18:50:18 +03:00
expect ( results [ 0 ] . logins ) . to . equal ( 1 ) ;
// cleanup to prevent needs for too much changes to other tests
2018-07-09 08:10:34 -04:00
return trx ( 'accounts' )
. delete ( )
. where ( 'id' , results [ 0 ] . id ) ;
2016-05-19 18:50:18 +03:00
} ) ;
} ) ;
} ) ;
2016-05-10 23:49:10 +03:00
} ) ;
2014-04-16 02:50:19 -04:00
} ;