Closed tomatosource closed 5 years ago
I am trying to test some code that uses a prepared statement (using postgres/sqlx), small example below.
The code is running in to nil pointer exceptions stemming from a nil statement pointer.
Is this a known shortcoming of lib? If so, are there any common workarounds?
Potentially related to https://github.com/DATA-DOG/go-txdb/issues/3?
Definitely happy to contribute if I can get pointed in a direction :)
func init() { txdb.Register("pgx", "postgres", "my connection string") } func NewTestDB(t *testing.T) *sqlx.DB { db, err := sqlx.Open("pgx", t.Name()) if err != nil { t.Fatal(err) } return db } func TestFoo(t *testing.T) { db := NewTestDB(t) stmt, err := db.PrepareContext(ctx, pq.CopyInSchema( "someschema", "sometable", "somecolumn" )) // stmt is nil here, no err }
Apologies - was able to reproduce without txdb - must be something else going on. Will update in future if I work it out for any future travellers.
Issue
I am trying to test some code that uses a prepared statement (using postgres/sqlx), small example below.
The code is running in to nil pointer exceptions stemming from a nil statement pointer.
Is this a known shortcoming of lib? If so, are there any common workarounds?
Potentially related to https://github.com/DATA-DOG/go-txdb/issues/3?
Definitely happy to contribute if I can get pointed in a direction :)
Example