mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
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.
66 lines
1.3 KiB
66 lines
1.3 KiB
8 years ago
|
// Copyright 2016 The Xorm Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a BSD-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
8 years ago
|
package builder
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
8 years ago
|
// Between implmentes between condition
|
||
8 years ago
|
type Between struct {
|
||
|
Col string
|
||
|
LessVal interface{}
|
||
|
MoreVal interface{}
|
||
|
}
|
||
|
|
||
|
var _ Cond = Between{}
|
||
|
|
||
8 years ago
|
// WriteTo write data to Writer
|
||
8 years ago
|
func (between Between) WriteTo(w Writer) error {
|
||
6 years ago
|
if _, err := fmt.Fprintf(w, "%s BETWEEN ", between.Col); err != nil {
|
||
8 years ago
|
return err
|
||
|
}
|
||
6 years ago
|
if lv, ok := between.LessVal.(expr); ok {
|
||
|
if err := lv.WriteTo(w); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
} else {
|
||
|
if _, err := fmt.Fprint(w, "?"); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
w.Append(between.LessVal)
|
||
|
}
|
||
|
|
||
|
if _, err := fmt.Fprint(w, " AND "); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
if mv, ok := between.MoreVal.(expr); ok {
|
||
|
if err := mv.WriteTo(w); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
} else {
|
||
|
if _, err := fmt.Fprint(w, "?"); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
w.Append(between.MoreVal)
|
||
|
}
|
||
|
|
||
8 years ago
|
return nil
|
||
|
}
|
||
|
|
||
8 years ago
|
// And implments And with other conditions
|
||
8 years ago
|
func (between Between) And(conds ...Cond) Cond {
|
||
|
return And(between, And(conds...))
|
||
|
}
|
||
|
|
||
8 years ago
|
// Or implments Or with other conditions
|
||
8 years ago
|
func (between Between) Or(conds ...Cond) Cond {
|
||
|
return Or(between, Or(conds...))
|
||
|
}
|
||
|
|
||
8 years ago
|
// IsValid tests if the condition is valid
|
||
8 years ago
|
func (between Between) IsValid() bool {
|
||
|
return len(between.Col) > 0
|
||
|
}
|