cond_between.go 945 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. // Between implmentes between condition
  7. type Between struct {
  8. Col string
  9. LessVal interface{}
  10. MoreVal interface{}
  11. }
  12. var _ Cond = Between{}
  13. // WriteTo write data to Writer
  14. func (between Between) WriteTo(w Writer) error {
  15. if _, err := fmt.Fprintf(w, "%s BETWEEN ? AND ?", between.Col); err != nil {
  16. return err
  17. }
  18. w.Append(between.LessVal, between.MoreVal)
  19. return nil
  20. }
  21. // And implments And with other conditions
  22. func (between Between) And(conds ...Cond) Cond {
  23. return And(between, And(conds...))
  24. }
  25. // Or implments Or with other conditions
  26. func (between Between) Or(conds ...Cond) Cond {
  27. return Or(between, Or(conds...))
  28. }
  29. // IsValid tests if the condition is valid
  30. func (between Between) IsValid() bool {
  31. return len(between.Col) > 0
  32. }