github.com/acoshift/pgsql@v0.15.3/int64_test.go (about) 1 package pgsql_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/acoshift/pgsql" 9 ) 10 11 func TestNullInt64(t *testing.T) { 12 t.Parallel() 13 14 db := open(t) 15 defer db.Close() 16 17 _, err := db.Exec(` 18 drop table if exists test_pgsql_null_int64; 19 create table test_pgsql_null_int64 ( 20 id int primary key, 21 value int 22 ); 23 insert into test_pgsql_null_int64 ( 24 id, value 25 ) values 26 (0, 1), 27 (1, null); 28 `) 29 if !assert.NoError(t, err) { 30 return 31 } 32 defer db.Exec(`drop table test_pgsql_null_int64`) 33 34 t.Run("Scan", func(t *testing.T) { 35 { 36 var p int64 37 err = db.QueryRow(`select value from test_pgsql_null_int64 where id = 0`).Scan(pgsql.NullInt64(&p)) 38 assert.NoError(t, err) 39 assert.Equal(t, int64(1), p) 40 } 41 42 { 43 var p int64 44 err = db.QueryRow(`select value from test_pgsql_null_int64 where id = 1`).Scan(pgsql.NullInt64(&p)) 45 assert.NoError(t, err) 46 assert.Equal(t, int64(0), p) 47 } 48 }) 49 }