Compare commits
No commits in common. "dbd51ff4759e398c6facd2af6540562e4469424b" and "fa5def962c0bcadbdd7bdc43131f8fcfa54d30bc" have entirely different histories.
dbd51ff475
...
fa5def962c
37
option.go
37
option.go
@ -425,9 +425,9 @@ func optionToSql(o *Option) (sqlBuildResult string, bindValue []any) {
|
|||||||
}
|
}
|
||||||
if reflect.TypeOf(fieldValue).Kind() == reflect.Slice {
|
if reflect.TypeOf(fieldValue).Kind() == reflect.Slice {
|
||||||
// 传入数组, in语句
|
// 传入数组, in语句
|
||||||
placeholder, dataList := parseInSql(fieldValue)
|
sqlBuildResultBlockList = append(sqlBuildResultBlockList, "`"+fieldName+"` in (?)")
|
||||||
sqlBuildResultBlockList = append(sqlBuildResultBlockList, "`"+fieldName+"` IN ("+placeholder+")")
|
byteData, _ := json.Marshal(fieldValue)
|
||||||
bindValue = append(bindValue, dataList...)
|
bindValue = append(bindValue, strings.TrimRight(strings.TrimLeft(string(byteData), "["), "]"))
|
||||||
} else {
|
} else {
|
||||||
sqlBuildResultBlockList = append(sqlBuildResultBlockList, "`"+fieldName+"` = ?")
|
sqlBuildResultBlockList = append(sqlBuildResultBlockList, "`"+fieldName+"` = ?")
|
||||||
bindValue = append(bindValue, fieldValue)
|
bindValue = append(bindValue, fieldValue)
|
||||||
@ -442,16 +442,16 @@ func optionToSql(o *Option) (sqlBuildResult string, bindValue []any) {
|
|||||||
// in 语句
|
// in 语句
|
||||||
// 传入数组, in语句
|
// 传入数组, in语句
|
||||||
for fieldName, fieldValue := range o.In {
|
for fieldName, fieldValue := range o.In {
|
||||||
placeholder, dataList := parseInSql(fieldValue)
|
sqlBuildResultBlockList = append(sqlBuildResultBlockList, "`"+fieldName+"` in (?)")
|
||||||
sqlBuildResultBlockList = append(sqlBuildResultBlockList, "`"+fieldName+"` IN ("+placeholder+")")
|
byteData, _ := json.Marshal(fieldValue)
|
||||||
bindValue = append(bindValue, dataList...)
|
bindValue = append(bindValue, strings.TrimRight(strings.TrimLeft(string(byteData), "["), "]"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// not in 语句
|
// not in 语句
|
||||||
for fieldName, fieldValue := range o.NotIn {
|
for fieldName, fieldValue := range o.NotIn {
|
||||||
placeholder, dataList := parseInSql(fieldValue)
|
sqlBuildResultBlockList = append(sqlBuildResultBlockList, "`"+fieldName+"` NOT IN (?)")
|
||||||
sqlBuildResultBlockList = append(sqlBuildResultBlockList, "`"+fieldName+"` NOT IN ("+placeholder+")")
|
byteData, _ := json.Marshal(fieldValue)
|
||||||
bindValue = append(bindValue, dataList...)
|
bindValue = append(bindValue, strings.TrimRight(strings.TrimLeft(string(byteData), "["), "]"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// like 语句
|
// like 语句
|
||||||
@ -489,22 +489,3 @@ func optionToSql(o *Option) (sqlBuildResult string, bindValue []any) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseInSql 解析in语句需要绑定占位符以及数据
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 22:07 2024/8/9
|
|
||||||
func parseInSql(fieldValue any) (string, []any) {
|
|
||||||
byteData, _ := json.Marshal(fieldValue)
|
|
||||||
var dataList []any
|
|
||||||
decoder := json.NewDecoder(strings.NewReader(string(byteData)))
|
|
||||||
decoder.UseNumber()
|
|
||||||
_ = decoder.Decode(&dataList)
|
|
||||||
// 生成占位符
|
|
||||||
placeholderList := make([]string, 0)
|
|
||||||
for i := 0; i < len(dataList); i++ {
|
|
||||||
placeholderList = append(placeholderList, "?")
|
|
||||||
}
|
|
||||||
return strings.Join(placeholderList, ","), dataList
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user