You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
746 B

  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) WriteTo(w Writer) error {
  16. if _, err := fmt.Fprint(w, expr.sql); err != nil {
  17. return err
  18. }
  19. w.Append(expr.args...)
  20. return nil
  21. }
  22. func (expr expr) And(conds ...Cond) Cond {
  23. return And(expr, And(conds...))
  24. }
  25. func (expr expr) Or(conds ...Cond) Cond {
  26. return Or(expr, Or(conds...))
  27. }
  28. func (expr expr) IsValid() bool {
  29. return len(expr.sql) > 0
  30. }