(t *testing.T)
| 467 | } |
| 468 | |
| 469 | func TestJoinQuery(t *testing.T) { |
| 470 | type Employee struct { |
| 471 | Name string |
| 472 | ID int64 |
| 473 | // BossID is an id into the employee table |
| 474 | BossID sql.NullInt64 `db:"boss_id"` |
| 475 | } |
| 476 | type Boss Employee |
| 477 | |
| 478 | RunWithSchema(defaultSchema, t, func(db *DB, t *testing.T, now string) { |
| 479 | loadDefaultFixture(db, t) |
| 480 | |
| 481 | var employees []struct { |
| 482 | Employee |
| 483 | Boss `db:"boss"` |
| 484 | } |
| 485 | |
| 486 | err := db.Select( |
| 487 | &employees, |
| 488 | `SELECT employees.*, boss.id "boss.id", boss.name "boss.name" FROM employees |
| 489 | JOIN employees AS boss ON employees.boss_id = boss.id`) |
| 490 | if err != nil { |
| 491 | t.Fatal(err) |
| 492 | } |
| 493 | |
| 494 | for _, em := range employees { |
| 495 | if len(em.Employee.Name) == 0 { |
| 496 | t.Errorf("Expected non zero lengthed name.") |
| 497 | } |
| 498 | if em.Employee.BossID.Int64 != em.Boss.ID { |
| 499 | t.Errorf("Expected boss ids to match") |
| 500 | } |
| 501 | } |
| 502 | }) |
| 503 | } |
| 504 | |
| 505 | func TestJoinQueryNamedPointerStructs(t *testing.T) { |
| 506 | type Employee struct { |
nothing calls this directly
no test coverage detected