本站源代码
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.

44 lines
829B

  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. }
上海开阖软件有限公司 沪ICP备12045867号-1