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

Method TestOptionTypes

adapter/postgresql/postgresql_test.go:589–740  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

587}
588
589func (s *AdapterTests) TestOptionTypes() {
590 sess := s.Session()
591
592 optionTypes := sess.Collection("option_types")
593 err := optionTypes.Truncate()
594 s.NoError(err)
595
596 // TODO: lets do some benchmarking on these auto-wrapped option types..
597
598 // TODO: add nullable jsonb field mapped to a []string
599
600 // A struct with wrapped option types defined in the struct tags
601 // for postgres string array and jsonb types
602 type optionType struct {
603 ID int64 `db:"id,omitempty"`
604 Name string `db:"name"`
605 Tags []string `db:"tags"`
606 Settings map[string]interface{} `db:"settings"`
607 }
608
609 // Item 1
610 item1 := optionType{
611 Name: "Food",
612 Tags: []string{"toronto", "pizza"},
613 Settings: map[string]interface{}{"a": 1, "b": 2},
614 }
615
616 record, err := optionTypes.Insert(item1)
617 s.NoError(err)
618
619 if pk, ok := record.ID().(int64); !ok || pk == 0 {
620 s.T().Errorf("Expecting an ID.")
621 }
622
623 var item1Chk optionType
624 err = optionTypes.Find(record).One(&item1Chk)
625 s.NoError(err)
626
627 s.Equal(float64(1), item1Chk.Settings["a"])
628 s.Equal("toronto", item1Chk.Tags[0])
629
630 // Item 1 B
631 item1b := &optionType{
632 Name: "Golang",
633 Tags: []string{"love", "it"},
634 Settings: map[string]interface{}{"go": 1, "lang": 2},
635 }
636
637 record, err = optionTypes.Insert(item1b)
638 s.NoError(err)
639
640 if pk, ok := record.ID().(int64); !ok || pk == 0 {
641 s.T().Errorf("Expecting an ID.")
642 }
643
644 var item1bChk optionType
645 err = optionTypes.Find(record).One(&item1bChk)
646 s.NoError(err)

Callers

nothing calls this directly

Calls 9

SessionMethod · 0.65
CollectionMethod · 0.65
TruncateMethod · 0.65
InsertMethod · 0.65
IDMethod · 0.65
ErrorfMethod · 0.65
OneMethod · 0.65
FindMethod · 0.65
UpdateMethod · 0.65

Tested by

no test coverage detected