@ -1,6 +1,7 @@
package sqlx
import (
"context"
"database/sql"
"errors"
"testing"
@ -16,7 +17,7 @@ func TestUnmarshalRowBool(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value bool
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . True ( t , value )
@ -29,7 +30,7 @@ func TestUnmarshalRowBoolNotSettable(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value bool
assert . NotNil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . NotNil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
} )
@ -41,7 +42,7 @@ func TestUnmarshalRowInt(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value int
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , 2 , value )
@ -54,7 +55,7 @@ func TestUnmarshalRowInt8(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value int8
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , int8 ( 3 ) , value )
@ -67,7 +68,7 @@ func TestUnmarshalRowInt16(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value int16
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . Equal ( t , int16 ( 4 ) , value )
@ -80,7 +81,7 @@ func TestUnmarshalRowInt32(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value int32
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . Equal ( t , int32 ( 5 ) , value )
@ -93,7 +94,7 @@ func TestUnmarshalRowInt64(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value int64
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , int64 ( 6 ) , value )
@ -106,7 +107,7 @@ func TestUnmarshalRowUint(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value uint
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , uint ( 2 ) , value )
@ -119,7 +120,7 @@ func TestUnmarshalRowUint8(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value uint8
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , uint8 ( 3 ) , value )
@ -132,7 +133,7 @@ func TestUnmarshalRowUint16(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value uint16
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , uint16 ( 4 ) , value )
@ -145,7 +146,7 @@ func TestUnmarshalRowUint32(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value uint32
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , uint32 ( 5 ) , value )
@ -158,7 +159,7 @@ func TestUnmarshalRowUint64(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value uint64
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , uint16 ( 6 ) , value )
@ -171,7 +172,7 @@ func TestUnmarshalRowFloat32(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value float32
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , float32 ( 7 ) , value )
@ -184,7 +185,7 @@ func TestUnmarshalRowFloat64(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value float64
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , float64 ( 8 ) , value )
@ -198,7 +199,7 @@ func TestUnmarshalRowString(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value string
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -215,7 +216,7 @@ func TestUnmarshalRowStruct(t *testing.T) {
rs := sqlmock . NewRows ( [ ] string { "name" , "age" } ) . FromCSVString ( "liao,5" )
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( value , rows , true )
} , "select name, age from users where user=?" , "anyone" ) )
assert . Equal ( t , "liao" , value . Name )
@ -233,7 +234,7 @@ func TestUnmarshalRowStructWithTags(t *testing.T) {
rs := sqlmock . NewRows ( [ ] string { "name" , "age" } ) . FromCSVString ( "liao,5" )
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( value , rows , true )
} , "select name, age from users where user=?" , "anyone" ) )
assert . Equal ( t , "liao" , value . Name )
@ -251,7 +252,7 @@ func TestUnmarshalRowStructWithTagsWrongColumns(t *testing.T) {
rs := sqlmock . NewRows ( [ ] string { "name" } ) . FromCSVString ( "liao" )
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
assert . NotNil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . NotNil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( value , rows , true )
} , "select name, age from users where user=?" , "anyone" ) )
} )
@ -264,7 +265,7 @@ func TestUnmarshalRowsBool(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] bool
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -278,7 +279,7 @@ func TestUnmarshalRowsInt(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] int
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -292,7 +293,7 @@ func TestUnmarshalRowsInt8(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] int8
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -306,7 +307,7 @@ func TestUnmarshalRowsInt16(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] int16
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -320,7 +321,7 @@ func TestUnmarshalRowsInt32(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] int32
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -334,7 +335,7 @@ func TestUnmarshalRowsInt64(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] int64
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -348,7 +349,7 @@ func TestUnmarshalRowsUint(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] uint
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -362,7 +363,7 @@ func TestUnmarshalRowsUint8(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] uint8
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -376,7 +377,7 @@ func TestUnmarshalRowsUint16(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] uint16
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -390,7 +391,7 @@ func TestUnmarshalRowsUint32(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] uint32
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -404,7 +405,7 @@ func TestUnmarshalRowsUint64(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] uint64
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -418,7 +419,7 @@ func TestUnmarshalRowsFloat32(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] float32
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -432,7 +433,7 @@ func TestUnmarshalRowsFloat64(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] float64
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -446,7 +447,7 @@ func TestUnmarshalRowsString(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] string
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -462,7 +463,7 @@ func TestUnmarshalRowsBoolPtr(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] * bool
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -478,7 +479,7 @@ func TestUnmarshalRowsIntPtr(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] * int
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -494,7 +495,7 @@ func TestUnmarshalRowsInt8Ptr(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] * int8
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -510,7 +511,7 @@ func TestUnmarshalRowsInt16Ptr(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] * int16
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -526,7 +527,7 @@ func TestUnmarshalRowsInt32Ptr(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] * int32
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -542,7 +543,7 @@ func TestUnmarshalRowsInt64Ptr(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] * int64
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -558,7 +559,7 @@ func TestUnmarshalRowsUintPtr(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] * uint
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -574,7 +575,7 @@ func TestUnmarshalRowsUint8Ptr(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] * uint8
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -590,7 +591,7 @@ func TestUnmarshalRowsUint16Ptr(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] * uint16
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -606,7 +607,7 @@ func TestUnmarshalRowsUint32Ptr(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] * uint32
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -622,7 +623,7 @@ func TestUnmarshalRowsUint64Ptr(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] * uint64
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -638,7 +639,7 @@ func TestUnmarshalRowsFloat32Ptr(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] * float32
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -654,7 +655,7 @@ func TestUnmarshalRowsFloat64Ptr(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] * float64
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -670,7 +671,7 @@ func TestUnmarshalRowsStringPtr(t *testing.T) {
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
var value [ ] * string
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select value from users where user=?" , "anyone" ) )
assert . EqualValues ( t , expect , value )
@ -699,7 +700,7 @@ func TestUnmarshalRowsStruct(t *testing.T) {
runOrmTest ( t , func ( db * sql . DB , mock sqlmock . Sqlmock ) {
rs := sqlmock . NewRows ( [ ] string { "name" , "age" } ) . FromCSVString ( "first,2\nsecond,3" )
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select name, age from users where user=?" , "anyone" ) )
@ -739,7 +740,7 @@ func TestUnmarshalRowsStructWithNullStringType(t *testing.T) {
rs := sqlmock . NewRows ( [ ] string { "name" , "value" } ) . AddRow (
"first" , "firstnullstring" ) . AddRow ( "second" , nil )
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select name, age from users where user=?" , "anyone" ) )
@ -773,7 +774,7 @@ func TestUnmarshalRowsStructWithTags(t *testing.T) {
runOrmTest ( t , func ( db * sql . DB , mock sqlmock . Sqlmock ) {
rs := sqlmock . NewRows ( [ ] string { "name" , "age" } ) . FromCSVString ( "first,2\nsecond,3" )
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select name, age from users where user=?" , "anyone" ) )
@ -814,7 +815,7 @@ func TestUnmarshalRowsStructAndEmbeddedAnonymousStructWithTags(t *testing.T) {
runOrmTest ( t , func ( db * sql . DB , mock sqlmock . Sqlmock ) {
rs := sqlmock . NewRows ( [ ] string { "name" , "age" , "value" } ) . FromCSVString ( "first,2,3\nsecond,3,4" )
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select name, age, value from users where user=?" , "anyone" ) )
@ -856,7 +857,7 @@ func TestUnmarshalRowsStructAndEmbeddedStructPtrAnonymousWithTags(t *testing.T)
runOrmTest ( t , func ( db * sql . DB , mock sqlmock . Sqlmock ) {
rs := sqlmock . NewRows ( [ ] string { "name" , "age" , "value" } ) . FromCSVString ( "first,2,3\nsecond,3,4" )
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select name, age, value from users where user=?" , "anyone" ) )
@ -890,7 +891,7 @@ func TestUnmarshalRowsStructPtr(t *testing.T) {
runOrmTest ( t , func ( db * sql . DB , mock sqlmock . Sqlmock ) {
rs := sqlmock . NewRows ( [ ] string { "name" , "age" } ) . FromCSVString ( "first,2\nsecond,3" )
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select name, age from users where user=?" , "anyone" ) )
@ -923,7 +924,7 @@ func TestUnmarshalRowsStructWithTagsPtr(t *testing.T) {
runOrmTest ( t , func ( db * sql . DB , mock sqlmock . Sqlmock ) {
rs := sqlmock . NewRows ( [ ] string { "name" , "age" } ) . FromCSVString ( "first,2\nsecond,3" )
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select name, age from users where user=?" , "anyone" ) )
@ -956,7 +957,7 @@ func TestUnmarshalRowsStructWithTagsPtrWithInnerPtr(t *testing.T) {
runOrmTest ( t , func ( db * sql . DB , mock sqlmock . Sqlmock ) {
rs := sqlmock . NewRows ( [ ] string { "name" , "age" } ) . FromCSVString ( "first,2\nsecond,3" )
mock . ExpectQuery ( "select (.+) from users where user=?" ) . WithArgs ( "anyone" ) . WillReturnRows ( rs )
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRows ( & value , rows , true )
} , "select name, age from users where user=?" , "anyone" ) )
@ -976,7 +977,7 @@ func TestCommonSqlConn_QueryRowOptional(t *testing.T) {
User string ` db:"user" `
Age int ` db:"age" `
}
assert . Nil ( t , query ( db, func ( rows * sql . Rows ) error {
assert . Nil ( t , query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
return unmarshalRow ( & r , rows , false )
} , "select age from users where user=?" , "anyone" ) )
assert . Empty ( t , r . User )
@ -1027,7 +1028,7 @@ func TestUnmarshalRowError(t *testing.T) {
User string ` db:"user" `
Age int ` db:"age" `
}
test . validate ( query ( db, func ( rows * sql . Rows ) error {
test . validate ( query ( context. Background ( ) , db, func ( rows * sql . Rows ) error {
scanner := mockedScanner {
colErr : test . colErr ,
scanErr : test . scanErr ,