(t *testing.T)
| 416 | } |
| 417 | |
| 418 | func TestNamedQueryContext(t *testing.T) { |
| 419 | var schema = Schema{ |
| 420 | create: ` |
| 421 | CREATE TABLE place ( |
| 422 | id integer PRIMARY KEY, |
| 423 | name text NULL |
| 424 | ); |
| 425 | CREATE TABLE person ( |
| 426 | first_name text NULL, |
| 427 | last_name text NULL, |
| 428 | email text NULL |
| 429 | ); |
| 430 | CREATE TABLE placeperson ( |
| 431 | first_name text NULL, |
| 432 | last_name text NULL, |
| 433 | email text NULL, |
| 434 | place_id integer NULL |
| 435 | ); |
| 436 | CREATE TABLE jsperson ( |
| 437 | "FIRST" text NULL, |
| 438 | last_name text NULL, |
| 439 | "EMAIL" text NULL |
| 440 | );`, |
| 441 | drop: ` |
| 442 | drop table person; |
| 443 | drop table jsperson; |
| 444 | drop table place; |
| 445 | drop table placeperson; |
| 446 | `, |
| 447 | } |
| 448 | |
| 449 | RunWithSchemaContext(context.Background(), schema, t, func(ctx context.Context, db *DB, t *testing.T) { |
| 450 | type Person struct { |
| 451 | FirstName sql.NullString `db:"first_name"` |
| 452 | LastName sql.NullString `db:"last_name"` |
| 453 | Email sql.NullString |
| 454 | } |
| 455 | |
| 456 | p := Person{ |
| 457 | FirstName: sql.NullString{String: "ben", Valid: true}, |
| 458 | LastName: sql.NullString{String: "doe", Valid: true}, |
| 459 | Email: sql.NullString{String: "ben@doe.com", Valid: true}, |
| 460 | } |
| 461 | |
| 462 | q1 := `INSERT INTO person (first_name, last_name, email) VALUES (:first_name, :last_name, :email)` |
| 463 | _, err := db.NamedExecContext(ctx, q1, p) |
| 464 | if err != nil { |
| 465 | log.Fatal(err) |
| 466 | } |
| 467 | |
| 468 | p2 := &Person{} |
| 469 | rows, err := db.NamedQueryContext(ctx, "SELECT * FROM person WHERE first_name=:first_name", p) |
| 470 | if err != nil { |
| 471 | log.Fatal(err) |
| 472 | } |
| 473 | for rows.Next() { |
| 474 | err = rows.StructScan(p2) |
| 475 | if err != nil { |
nothing calls this directly
no test coverage detected