MCPcopy Index your code
hub / github.com/upper/db / TestInlineStructs

Method TestInlineStructs

internal/testsuite/sql_suite.go:646–696  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

644}
645
646func (s *SQLTestSuite) TestInlineStructs() {
647 type reviewTypeDetails struct {
648 Name string `db:"name"`
649 Comments string `db:"comments"`
650 Created time.Time `db:"created"`
651 }
652
653 type reviewType struct {
654 ID int64 `db:"id,omitempty"`
655 PublicationID int64 `db:"publication_id"`
656 Details reviewTypeDetails `db:",inline"`
657 }
658
659 sess := s.Session()
660
661 review := sess.Collection("review")
662
663 err := review.Truncate()
664 s.NoError(err)
665
666 rec := reviewType{
667 PublicationID: 123,
668 Details: reviewTypeDetails{
669 Name: "..name..",
670 Comments: "..comments..",
671 },
672 }
673
674 testTimeZone := time.UTC
675 switch s.Adapter() {
676 case "mysql": // MySQL uses a global time zone
677 testTimeZone = defaultTimeLocation
678 }
679
680 createdAt := time.Date(2016, time.January, 1, 2, 3, 4, 0, testTimeZone)
681 rec.Details.Created = createdAt
682
683 record, err := review.Insert(rec)
684 s.NoError(err)
685 s.NotZero(record.ID().(int64))
686
687 rec.ID = record.ID().(int64)
688
689 var recChk reviewType
690 res := review.Find()
691
692 err = res.One(&recChk)
693 s.NoError(err)
694
695 s.Equal(rec, recChk)
696}
697
698func (s *SQLTestSuite) TestUpdate() {
699 sess := s.Session()

Callers

nothing calls this directly

Calls 8

SessionMethod · 0.65
CollectionMethod · 0.65
TruncateMethod · 0.65
AdapterMethod · 0.65
InsertMethod · 0.65
IDMethod · 0.65
FindMethod · 0.65
OneMethod · 0.65

Tested by

no test coverage detected