Skip to content

Commit

Permalink
feat(sqlgen): allow any type of value for prepared mode
Browse files Browse the repository at this point in the history
  • Loading branch information
yz89122 committed Apr 28, 2022
1 parent 31d438d commit fdc79d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions sqlgen/expression_sql_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ func (esg *expressionSQLGenerator) reflectSQL(b sb.SQLBuilder, val interface{})
case util.IsBool(valKind):
esg.Generate(b, v.Bool())
default:
// allow any type of value for prepared mode
if b.IsPrepared() {
esg.placeHolderSQL(b, val)

return
}

b.SetError(errors.NewEncodeError(val))
}
}
Expand Down
4 changes: 2 additions & 2 deletions sqlgen/expression_sql_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ func (esgs *expressionSQLGeneratorSuite) TestGenerate_Invalid() {
)
}

func (esgs *expressionSQLGeneratorSuite) TestGenerate_UnsupportedType() {
func (esgs *expressionSQLGeneratorSuite) TestGenerate_OtherType() {
type strct struct{}
esgs.assertCases(
sqlgen.NewExpressionSQLGenerator("test", sqlgen.DefaultDialectOptions()),
expressionTestCase{val: strct{}, err: "goqu_encode_error: Unable to encode value {}"},
expressionTestCase{val: strct{}, err: "goqu_encode_error: Unable to encode value {}", isPrepared: true},
expressionTestCase{val: strct{}, sql: "?", isPrepared: true, args: []interface{}{strct{}}},
)
}

Expand Down

0 comments on commit fdc79d4

Please sign in to comment.