42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package mydb
|
|
|
|
import "git.hexq.cn/tiglog/mydb/internal/adapter"
|
|
|
|
// OrExpr represents a logical expression joined by logical disjunction (OR).
|
|
type OrExpr struct {
|
|
*adapter.LogicalExprGroup
|
|
}
|
|
|
|
// Or adds more expressions to the group.
|
|
func (o *OrExpr) Or(orConds ...LogicalExpr) *OrExpr {
|
|
var fn func(*[]LogicalExpr) error
|
|
if len(orConds) > 0 {
|
|
fn = func(in *[]LogicalExpr) error {
|
|
*in = append(*in, orConds...)
|
|
return nil
|
|
}
|
|
}
|
|
return &OrExpr{o.LogicalExprGroup.Frame(fn)}
|
|
}
|
|
|
|
// Empty returns false if the expressions has zero conditions.
|
|
func (o *OrExpr) Empty() bool {
|
|
return o.LogicalExprGroup.Empty()
|
|
}
|
|
|
|
// Or joins conditions under logical disjunction. Conditions can be represented
|
|
// by `db.Cond{}`, `db.Or()` or `db.And()`.
|
|
//
|
|
// Example:
|
|
//
|
|
// // year = 2012 OR year = 1987
|
|
// db.Or(
|
|
// db.Cond{"year": 2012},
|
|
// db.Cond{"year": 1987},
|
|
// )
|
|
func Or(conds ...LogicalExpr) *OrExpr {
|
|
return &OrExpr{adapter.NewLogicalExprGroup(adapter.LogicalOperatorOr, defaultJoin(conds...)...)}
|
|
}
|
|
|
|
var _ = adapter.LogicalExpr(&OrExpr{})
|