| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 | 
							- package om
 
- import (
 
- 	"strings"
 
- )
 
- type Condition struct {
 
- 	FieldName string
 
- 	Value     any
 
- 	Opt       string
 
- }
 
- func NewCondition(fieldName string, value any, args ...string) Condition {
 
- 	opt := Equ
 
- 	if len(args) > 0 {
 
- 		opt, _ = GetValidOpt(args[0], Equ)
 
- 	}
 
- 	return Condition{FieldName: fieldName, Value: value, Opt: opt}
 
- }
 
- const (
 
- 	Equ   = "="
 
- 	Like  = "LIKE"
 
- 	Start = "START"
 
- 	End   = "END"
 
- 	Le    = "<"
 
- 	Ge    = ">"
 
- 	UnEqu = "<>"
 
- )
 
- const (
 
- 	AND = "AND"
 
- 	OR  = "OR"
 
- )
 
- const (
 
- 	ASC  = "ASC"
 
- 	DESC = "DESC"
 
- )
 
- func GetValidOpt(s string, ps ...string) (string, bool) {
 
- 	ts := strings.ToUpper(strings.TrimSpace(s))
 
- 	switch ts {
 
- 	case Equ, Like, Start, End, Le, Ge, OR, UnEqu:
 
- 		return ts, true
 
- 	}
 
- 	if len(ps) > 0 {
 
- 		return ps[0], false
 
- 	}
 
- 	return "", false
 
- }
 
 
  |