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

Method Clauses

chainable_api.go:38–56  ·  chainable_api.go::DB.Clauses

Clauses Add clauses This supports both standard clauses (clause.OrderBy, clause.Limit, clause.Where) and more advanced techniques like specifying lock strength and optimizer hints. See the [docs] for more depth. // add a simple limit clause db.Clauses(clause.Limit{Limit: 1}).Find(&User{}) // te

(conds ...clause.Expression)

Source from the content-addressed store, hash-verified

36//
37// [docs]: https://gorm.io/docs/sql_builder.html#Clauses
38func (db *DB) Clauses(conds ...clause.Expression) (tx *DB) {
39 tx = db.getInstance()
40 var whereConds []interface{}
41
42 for _, cond := range conds {
43 if c, ok := cond.(clause.Interface); ok {
44 tx.Statement.AddClause(c)
45 } else if optimizer, ok := cond.(StatementModifier); ok {
46 optimizer.ModifyStatement(tx.Statement)
47 } else {
48 whereConds = append(whereConds, cond)
49 }
50 }
51
52 if len(whereConds) > 0 {
53 tx.Statement.AddClause(clause.Where{Exprs: tx.Statement.BuildCondition(whereConds[0], whereConds[1:]...)})
54 }
55 return
56}
57
58var tableRegexp = regexp.MustCompile(`(?i)(?:.+? AS (\w+)\s*(?:$|,)|^\w+\s+(\w+)$)`)
59

Callers 15

SaveMethod · 0.80
FindInBatchesMethod · 0.80
GFunction · 0.80
PreloadMethod · 0.80
UpdateMethod · 0.80
ReplaceMethod · 0.80
DeleteMethod · 0.80
buildConditionMethod · 0.80
SaveAfterAssociationsFunction · 0.80
saveAssociationsFunction · 0.80
DeleteBeforeAssociationsFunction · 0.80
TestUpsertFunction · 0.80

Calls 4

getInstanceMethod · 0.95
AddClauseMethod · 0.80
BuildConditionMethod · 0.80
ModifyStatementMethod · 0.65

Tested by 15

TestUpsertFunction · 0.64
TestUpsertSliceFunction · 0.64
TestSoftDeleteReturningFunction · 0.64
TestDeleteReturningFunction · 0.64
TestUpdateReturningFunction · 0.64
TestUpdateFromFunction · 0.64
TestOrFunction · 0.64
TestOrderFunction · 0.64
TestOrderWithAllFieldsFunction · 0.64