value format refactoring
This commit is contained in:
parent
6a0d065664
commit
f6b5cd9c12
30
scope.go
30
scope.go
@ -573,29 +573,13 @@ func (scope *Scope) buildCondition(clause map[string]interface{}, include bool)
|
|||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
var sqls []string
|
var sqls []string
|
||||||
for key, value := range value {
|
for key, value := range value {
|
||||||
if value != nil {
|
sqls = append(sqls, scope.formatValue(quotedTableName, key, equalSQL, value, include))
|
||||||
sqls = append(sqls, fmt.Sprintf("(%v.%v %s %v)", quotedTableName, scope.Quote(key), equalSQL, scope.AddToVars(value)))
|
|
||||||
} else {
|
|
||||||
if !include {
|
|
||||||
sqls = append(sqls, fmt.Sprintf("(%v.%v IS NOT NULL)", quotedTableName, scope.Quote(key)))
|
|
||||||
} else {
|
|
||||||
sqls = append(sqls, fmt.Sprintf("(%v.%v IS NULL)", quotedTableName, scope.Quote(key)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return strings.Join(sqls, " AND ")
|
return strings.Join(sqls, " AND ")
|
||||||
case []sql.NamedArg:
|
case []sql.NamedArg:
|
||||||
var sqls []string
|
var sqls []string
|
||||||
for _, val := range value {
|
for _, val := range value {
|
||||||
if val.Value != nil {
|
sqls = append(sqls, scope.formatValue(quotedTableName, val.Name, equalSQL, val.Value, include))
|
||||||
sqls = append(sqls, fmt.Sprintf("(%v.%v %s %v)", quotedTableName, scope.Quote(val.Name), equalSQL, scope.AddToVars(val)))
|
|
||||||
} else {
|
|
||||||
if !include {
|
|
||||||
sqls = append(sqls, fmt.Sprintf("(%v.%v IS NOT NULL)", quotedTableName, scope.Quote(val.Name)))
|
|
||||||
} else {
|
|
||||||
sqls = append(sqls, fmt.Sprintf("(%v.%v IS NULL)", quotedTableName, scope.Quote(val.Name)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return strings.Join(sqls, " AND ")
|
return strings.Join(sqls, " AND ")
|
||||||
case interface{}:
|
case interface{}:
|
||||||
@ -683,6 +667,16 @@ func (scope *Scope) buildCondition(clause map[string]interface{}, include bool)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (scope *Scope) formatValue(qtm, key, equalSQL string, value interface{}, include bool) string {
|
||||||
|
if value != nil {
|
||||||
|
return fmt.Sprintf("(%v.%v %s %v)", qtm, scope.Quote(key), equalSQL, scope.AddToVars(value))
|
||||||
|
}
|
||||||
|
if include {
|
||||||
|
return fmt.Sprintf("(%v.%v IS NULL)", qtm, scope.Quote(key))
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("(%v.%v IS NOT NULL)", qtm, scope.Quote(key))
|
||||||
|
}
|
||||||
|
|
||||||
func (scope *Scope) buildSelectQuery(clause map[string]interface{}) (str string) {
|
func (scope *Scope) buildSelectQuery(clause map[string]interface{}) (str string) {
|
||||||
switch value := clause["query"].(type) {
|
switch value := clause["query"].(type) {
|
||||||
case string:
|
case string:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user