mirror of https://github.com/go-gorm/gorm.git
Fix Eq, Neq support slice of data
This commit is contained in:
parent
14e96080d8
commit
9abac96546
|
@ -241,7 +241,7 @@ func (eq Eq) Build(builder Builder) {
|
|||
if i > 0 {
|
||||
builder.WriteByte(',')
|
||||
}
|
||||
builder.AddVar(builder, rv.Index(i))
|
||||
builder.AddVar(builder, rv.Index(i).Interface())
|
||||
}
|
||||
builder.WriteByte(')')
|
||||
default:
|
||||
|
@ -272,7 +272,7 @@ func (neq Neq) Build(builder Builder) {
|
|||
if i > 0 {
|
||||
builder.WriteByte(',')
|
||||
}
|
||||
builder.AddVar(builder, rv.Index(i))
|
||||
builder.AddVar(builder, rv.Index(i).Interface())
|
||||
}
|
||||
builder.WriteByte(')')
|
||||
default:
|
||||
|
|
|
@ -105,13 +105,15 @@ func TestNamedExpr(t *testing.T) {
|
|||
func TestExpression(t *testing.T) {
|
||||
column := "column-name"
|
||||
results := []struct {
|
||||
Expressions []clause.Expression
|
||||
Result string
|
||||
Expressions []clause.Expression
|
||||
ExpectedVars []interface{}
|
||||
Result string
|
||||
}{{
|
||||
Expressions: []clause.Expression{
|
||||
clause.Eq{Column: column, Value: "column-value"},
|
||||
},
|
||||
Result: "`column-name` = ?",
|
||||
ExpectedVars: []interface{}{"column-value"},
|
||||
Result: "`column-name` = ?",
|
||||
}, {
|
||||
Expressions: []clause.Expression{
|
||||
clause.Eq{Column: column, Value: nil},
|
||||
|
@ -126,7 +128,8 @@ func TestExpression(t *testing.T) {
|
|||
Expressions: []clause.Expression{
|
||||
clause.Neq{Column: column, Value: "column-value"},
|
||||
},
|
||||
Result: "`column-name` <> ?",
|
||||
ExpectedVars: []interface{}{"column-value"},
|
||||
Result: "`column-name` <> ?",
|
||||
}, {
|
||||
Expressions: []clause.Expression{
|
||||
clause.Neq{Column: column, Value: nil},
|
||||
|
@ -140,12 +143,14 @@ func TestExpression(t *testing.T) {
|
|||
Expressions: []clause.Expression{
|
||||
clause.Eq{Column: column, Value: []string{"a", "b"}},
|
||||
},
|
||||
Result: "`column-name` IN (?,?)",
|
||||
ExpectedVars: []interface{}{"a", "b"},
|
||||
Result: "`column-name` IN (?,?)",
|
||||
}, {
|
||||
Expressions: []clause.Expression{
|
||||
clause.Neq{Column: column, Value: []string{"a", "b"}},
|
||||
},
|
||||
Result: "`column-name` NOT IN (?,?)",
|
||||
ExpectedVars: []interface{}{"a", "b"},
|
||||
Result: "`column-name` NOT IN (?,?)",
|
||||
}}
|
||||
|
||||
for idx, result := range results {
|
||||
|
@ -157,6 +162,10 @@ func TestExpression(t *testing.T) {
|
|||
if stmt.SQL.String() != result.Result {
|
||||
t.Errorf("generated SQL is not equal, expects %v, but got %v", result.Result, stmt.SQL.String())
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(result.ExpectedVars, stmt.Vars) {
|
||||
t.Errorf("generated vars is not equal, expects %v, but got %v", result.ExpectedVars, stmt.Vars)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue