cond_expr.go 829 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2016 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package builder
  5. import "fmt"
  6. type expr struct {
  7. sql string
  8. args []interface{}
  9. }
  10. var _ Cond = expr{}
  11. // Expr generate customerize SQL
  12. func Expr(sql string, args ...interface{}) Cond {
  13. return expr{sql, args}
  14. }
  15. func (expr expr) OpWriteTo(op string, w Writer) error {
  16. return expr.WriteTo(w)
  17. }
  18. func (expr expr) WriteTo(w Writer) error {
  19. if _, err := fmt.Fprint(w, expr.sql); err != nil {
  20. return err
  21. }
  22. w.Append(expr.args...)
  23. return nil
  24. }
  25. func (expr expr) And(conds ...Cond) Cond {
  26. return And(expr, And(conds...))
  27. }
  28. func (expr expr) Or(conds ...Cond) Cond {
  29. return Or(expr, Or(conds...))
  30. }
  31. func (expr expr) IsValid() bool {
  32. return len(expr.sql) > 0
  33. }