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

Method TestGroup

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

Source from the content-addressed store, hash-verified

940}
941
942func (s *SQLTestSuite) TestGroup() {
943 sess := s.Session()
944
945 type statsType struct {
946 Numeric int `db:"numeric"`
947 Value int `db:"value"`
948 }
949
950 stats := sess.Collection("stats_test")
951
952 err := stats.Truncate()
953 s.NoError(err)
954
955 // Adding row append.
956 for i := 0; i < 100; i++ {
957 numeric, value := rand.Intn(5), rand.Intn(100)
958 _, err := stats.Insert(statsType{numeric, value})
959 s.NoError(err)
960 }
961
962 // Testing GROUP BY
963 res := stats.Find().Select(
964 "numeric",
965 db.Raw("count(1) AS counter"),
966 db.Raw("sum(value) AS total"),
967 ).GroupBy("numeric")
968
969 var results []map[string]interface{}
970
971 err = res.All(&results)
972 s.NoError(err)
973
974 s.Equal(5, len(results))
975}
976
977func (s *SQLTestSuite) TestInsertAndDelete() {
978 sess := s.Session()

Callers

nothing calls this directly

Calls 9

RawMethod · 0.80
SessionMethod · 0.65
CollectionMethod · 0.65
TruncateMethod · 0.65
InsertMethod · 0.65
GroupByMethod · 0.65
SelectMethod · 0.65
FindMethod · 0.65
AllMethod · 0.65

Tested by

no test coverage detected