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)
| 36 | // |
| 37 | // [docs]: https://gorm.io/docs/sql_builder.html#Clauses |
| 38 | func (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 | |
| 58 | var tableRegexp = regexp.MustCompile(`(?i)(?:.+? AS (\w+)\s*(?:$|,)|^\w+\s+(\w+)$)`) |
| 59 |