| 382 | } |
| 383 | |
| 384 | func (s *SQLTestSuite) TestInsertIntoArtistsTable() { |
| 385 | sess := s.Session() |
| 386 | |
| 387 | artist := sess.Collection("artist") |
| 388 | |
| 389 | err := artist.Truncate() |
| 390 | s.NoError(err) |
| 391 | |
| 392 | itemMap := map[string]string{ |
| 393 | "name": "Ozzie", |
| 394 | } |
| 395 | |
| 396 | record, err := artist.Insert(itemMap) |
| 397 | s.NoError(err) |
| 398 | s.NotNil(record) |
| 399 | |
| 400 | if pk, ok := record.ID().(int64); !ok || pk == 0 { |
| 401 | s.T().Errorf("Expecting an ID.") |
| 402 | } |
| 403 | |
| 404 | // Attempt to append a struct. |
| 405 | itemStruct := struct { |
| 406 | Name string `db:"name"` |
| 407 | }{ |
| 408 | "Flea", |
| 409 | } |
| 410 | |
| 411 | record, err = artist.Insert(itemStruct) |
| 412 | s.NoError(err) |
| 413 | s.NotNil(record) |
| 414 | |
| 415 | if pk, ok := record.ID().(int64); !ok || pk == 0 { |
| 416 | s.T().Errorf("Expecting an ID.") |
| 417 | } |
| 418 | |
| 419 | // Attempt to append a tagged struct. |
| 420 | itemStruct2 := struct { |
| 421 | ArtistName string `db:"name"` |
| 422 | }{ |
| 423 | "Slash", |
| 424 | } |
| 425 | |
| 426 | record, err = artist.Insert(&itemStruct2) |
| 427 | s.NoError(err) |
| 428 | s.NotNil(record) |
| 429 | |
| 430 | if pk, ok := record.ID().(int64); !ok || pk == 0 { |
| 431 | s.T().Errorf("Expecting an ID.") |
| 432 | } |
| 433 | |
| 434 | itemStruct3 := artistType{ |
| 435 | Name: "Janus", |
| 436 | } |
| 437 | record, err = artist.Insert(&itemStruct3) |
| 438 | s.NoError(err) |
| 439 | if s.Adapter() != "ql" { |
| 440 | s.NotZero(record) // QL always inserts an ID. |
| 441 | } |