MCPcopy
hub / github.com/go-gorm/gorm / BenchmarkComplexSelect

Function BenchmarkComplexSelect

clause/benchmarks_test.go:29–58  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

27}
28
29func BenchmarkComplexSelect(b *testing.B) {
30 user, _ := schema.Parse(&tests.User{}, &sync.Map{}, db.NamingStrategy)
31
32 limit10 := 10
33 for i := 0; i < b.N; i++ {
34 stmt := gorm.Statement{DB: db, Table: user.Table, Schema: user, Clauses: map[string]clause.Clause{}}
35 clauses := []clause.Interface{
36 clause.Select{},
37 clause.From{},
38 clause.Where{Exprs: []clause.Expression{
39 clause.Eq{Column: clause.PrimaryColumn, Value: "1"},
40 clause.Gt{Column: "age", Value: 18},
41 clause.Or(clause.Neq{Column: "name", Value: "jinzhu"}),
42 }},
43 clause.Where{Exprs: []clause.Expression{
44 clause.Or(clause.Gt{Column: "score", Value: 100}, clause.Like{Column: "name", Value: "%linus%"}),
45 }},
46 clause.GroupBy{Columns: []clause.Column{{Name: "role"}}, Having: []clause.Expression{clause.Eq{"role", "admin"}}},
47 clause.Limit{Limit: &limit10, Offset: 20},
48 clause.OrderBy{Columns: []clause.OrderByColumn{{Column: clause.PrimaryColumn, Desc: true}}},
49 }
50
51 for _, clause := range clauses {
52 stmt.AddClause(clause)
53 }
54
55 stmt.Build("SELECT", "FROM", "WHERE", "GROUP BY", "LIMIT", "ORDER BY")
56 _ = stmt.SQL.String()
57 }
58}

Callers

nothing calls this directly

Calls 5

AddClauseMethod · 0.95
BuildMethod · 0.95
ParseFunction · 0.92
OrFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected