(t *testing.T)
| 331 | } |
| 332 | |
| 333 | func TestJoinQueryNamedPointerStructsContext(t *testing.T) { |
| 334 | type Employee struct { |
| 335 | Name string |
| 336 | ID int64 |
| 337 | // BossID is an id into the employee table |
| 338 | BossID sql.NullInt64 `db:"boss_id"` |
| 339 | } |
| 340 | type Boss Employee |
| 341 | |
| 342 | RunWithSchemaContext(context.Background(), defaultSchema, t, func(ctx context.Context, db *DB, t *testing.T) { |
| 343 | loadDefaultFixtureContext(ctx, db, t) |
| 344 | |
| 345 | var employees []struct { |
| 346 | Emp1 *Employee `db:"emp1"` |
| 347 | Emp2 *Employee `db:"emp2"` |
| 348 | *Boss `db:"boss"` |
| 349 | } |
| 350 | |
| 351 | err := db.SelectContext(ctx, |
| 352 | &employees, |
| 353 | `SELECT emp.name "emp1.name", emp.id "emp1.id", emp.boss_id "emp1.boss_id", |
| 354 | emp.name "emp2.name", emp.id "emp2.id", emp.boss_id "emp2.boss_id", |
| 355 | boss.id "boss.id", boss.name "boss.name" FROM employees AS emp |
| 356 | JOIN employees AS boss ON emp.boss_id = boss.id |
| 357 | `) |
| 358 | if err != nil { |
| 359 | t.Fatal(err) |
| 360 | } |
| 361 | |
| 362 | for _, em := range employees { |
| 363 | if len(em.Emp1.Name) == 0 || len(em.Emp2.Name) == 0 { |
| 364 | t.Errorf("Expected non zero lengthed name.") |
| 365 | } |
| 366 | if em.Emp1.BossID.Int64 != em.Boss.ID || em.Emp2.BossID.Int64 != em.Boss.ID { |
| 367 | t.Errorf("Expected boss ids to match") |
| 368 | } |
| 369 | } |
| 370 | }) |
| 371 | } |
| 372 | |
| 373 | func TestSelectSliceMapTimeContext(t *testing.T) { |
| 374 | RunWithSchemaContext(context.Background(), defaultSchema, t, func(ctx context.Context, db *DB, t *testing.T) { |
nothing calls this directly
no test coverage detected