接入搜索功能
This commit is contained in:
+79
-20
@@ -581,6 +581,15 @@ func (that *HoTimeDB) where(data Map) (string, []interface{}) {
|
||||
y++
|
||||
}
|
||||
if x == len(condition) && y == len(vcond) {
|
||||
|
||||
if reflect.ValueOf(v).Type().String() == "common.Slice" && len(v.(Slice)) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if reflect.ValueOf(v).Type().String() == "[]interface {}" && len(v.([]interface{})) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
tv, vv := that.varCond(k, v)
|
||||
|
||||
where += tv
|
||||
@@ -636,6 +645,7 @@ func (that *HoTimeDB) where(data Map) (string, []interface{}) {
|
||||
}
|
||||
|
||||
func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
||||
|
||||
where := ""
|
||||
res := make([]interface{}, 0)
|
||||
length := len(k)
|
||||
@@ -645,42 +655,72 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
||||
switch Substr(k, length-3, 3) {
|
||||
case "[>]":
|
||||
k = strings.Replace(k, "[>]", "", -1)
|
||||
where += "`" + k + "`>? "
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
}
|
||||
where += k + ">? "
|
||||
res = append(res, v)
|
||||
case "[<]":
|
||||
k = strings.Replace(k, "[<]", "", -1)
|
||||
where += "`" + k + "`<? "
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
}
|
||||
where += k + "<? "
|
||||
res = append(res, v)
|
||||
case "[!]":
|
||||
k = strings.Replace(k, "[!]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
}
|
||||
where, res = that.notIn(k, v, where, res)
|
||||
case "[#]":
|
||||
k = strings.Replace(k, "[#]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
}
|
||||
where += " " + k + "=" + ObjToStr(v)
|
||||
case "[#!]":
|
||||
k = strings.Replace(k, "[#!]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
}
|
||||
where += " " + k + "!=" + ObjToStr(v)
|
||||
case "[!#]":
|
||||
k = strings.Replace(k, "[!#]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
}
|
||||
where += " " + k + "!=" + ObjToStr(v)
|
||||
case "[~]":
|
||||
k = strings.Replace(k, "[~]", "", -1)
|
||||
where += "`" + k + "` LIKE ? "
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
}
|
||||
where += k + " LIKE ? "
|
||||
v = "%" + ObjToStr(v) + "%"
|
||||
res = append(res, v)
|
||||
case "[!~]": //左边任意
|
||||
k = strings.Replace(k, "[~]", "", -1)
|
||||
where += "`" + k + "` LIKE ? "
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
}
|
||||
where += k + " LIKE ? "
|
||||
v = "%" + ObjToStr(v)
|
||||
res = append(res, v)
|
||||
case "[~!]": //右边任意
|
||||
k = strings.Replace(k, "[~]", "", -1)
|
||||
where += "`" + k + "` LIKE ? "
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
}
|
||||
where += k + " LIKE ? "
|
||||
v = ObjToStr(v) + "%"
|
||||
res = append(res, v)
|
||||
case "[~~]": //手动任意
|
||||
k = strings.Replace(k, "[~]", "", -1)
|
||||
where += "`" + k + "` LIKE ? "
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
}
|
||||
where += k + " LIKE ? "
|
||||
//v = ObjToStr(v)
|
||||
res = append(res, v)
|
||||
default:
|
||||
@@ -691,25 +731,40 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
||||
switch Substr(k, length-4, 4) {
|
||||
case "[>=]":
|
||||
k = strings.Replace(k, "[>=]", "", -1)
|
||||
where += "`" + k + "`>=? "
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
}
|
||||
where += k + ">=? "
|
||||
res = append(res, v)
|
||||
case "[<=]":
|
||||
k = strings.Replace(k, "[<=]", "", -1)
|
||||
where += "`" + k + "`<=? "
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
}
|
||||
where += k + "<=? "
|
||||
res = append(res, v)
|
||||
case "[><]":
|
||||
k = strings.Replace(k, "[><]", "", -1)
|
||||
where += "`" + k + "` NOT BETWEEN ? AND ? "
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
}
|
||||
where += k + " NOT BETWEEN ? AND ? "
|
||||
res = append(res, v.(Slice)[0])
|
||||
res = append(res, v.(Slice)[1])
|
||||
case "[<>]":
|
||||
k = strings.Replace(k, "[<>]", "", -1)
|
||||
where += "`" + k + "` BETWEEN ? AND ? "
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
}
|
||||
where += k + " BETWEEN ? AND ? "
|
||||
res = append(res, v.(Slice)[0])
|
||||
res = append(res, v.(Slice)[1])
|
||||
default:
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
}
|
||||
if reflect.ValueOf(v).Type().String() == "common.Slice" {
|
||||
where += "`" + k + "` IN ("
|
||||
where += k + " IN ("
|
||||
res = append(res, v.(Slice)...)
|
||||
if len(v.(Slice)) == 0 {
|
||||
where += ") "
|
||||
@@ -725,7 +780,7 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
||||
}
|
||||
|
||||
} else {
|
||||
where += "`" + k + "`=? "
|
||||
where += k + "=? "
|
||||
res = append(res, v)
|
||||
}
|
||||
|
||||
@@ -737,12 +792,15 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
||||
where += " " + ObjToStr(v) + " "
|
||||
} else {
|
||||
//fmt.Println(reflect.ValueOf(v).Type().String())
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
}
|
||||
if v == nil {
|
||||
where += "`" + k + "` IS NULL"
|
||||
where += k + " IS NULL"
|
||||
} else if reflect.ValueOf(v).Type().String() == "common.Slice" {
|
||||
|
||||
//fmt.Println(v)
|
||||
where += "`" + k + "` IN ("
|
||||
where += k + " IN ("
|
||||
res = append(res, v.(Slice)...)
|
||||
for i := 0; i < len(v.(Slice)); i++ {
|
||||
if i+1 != len(v.(Slice)) {
|
||||
@@ -753,7 +811,8 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
||||
//res=append(res,(v.(Slice))[i])
|
||||
}
|
||||
} else if reflect.ValueOf(v).Type().String() == "[]interface {}" {
|
||||
where += "`" + k + "` IN ("
|
||||
|
||||
where += k + " IN ("
|
||||
res = append(res, v.([]interface{})...)
|
||||
for i := 0; i < len(v.([]interface{})); i++ {
|
||||
if i+1 != len(v.([]interface{})) {
|
||||
@@ -765,7 +824,7 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
||||
}
|
||||
} else {
|
||||
|
||||
where += "`" + k + "`=? "
|
||||
where += k + "=? "
|
||||
res = append(res, v)
|
||||
|
||||
}
|
||||
@@ -780,10 +839,10 @@ func (that *HoTimeDB) notIn(k string, v interface{}, where string, res []interfa
|
||||
//fmt.Println(reflect.ValueOf(v).Type().String())
|
||||
if v == nil {
|
||||
|
||||
where += "`" + k + "` IS NOT NULL "
|
||||
where += k + " IS NOT NULL "
|
||||
|
||||
} else if reflect.ValueOf(v).Type().String() == "common.Slice" {
|
||||
where += "`" + k + "` NOT IN ("
|
||||
where += k + " NOT IN ("
|
||||
res = append(res, v.(Slice)...)
|
||||
for i := 0; i < len(v.(Slice)); i++ {
|
||||
if i+1 != len(v.(Slice)) {
|
||||
@@ -794,7 +853,7 @@ func (that *HoTimeDB) notIn(k string, v interface{}, where string, res []interfa
|
||||
//res=append(res,(v.(Slice))[i])
|
||||
}
|
||||
} else if reflect.ValueOf(v).Type().String() == "[]interface {}" {
|
||||
where += "`" + k + "` NOT IN ("
|
||||
where += k + " NOT IN ("
|
||||
res = append(res, v.([]interface{})...)
|
||||
for i := 0; i < len(v.([]interface{})); i++ {
|
||||
if i+1 != len(v.([]interface{})) {
|
||||
@@ -806,7 +865,7 @@ func (that *HoTimeDB) notIn(k string, v interface{}, where string, res []interfa
|
||||
}
|
||||
} else {
|
||||
|
||||
where += "`" + k + "` !=? "
|
||||
where += k + " !=? "
|
||||
res = append(res, v)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user