From fdc79d421bde456e080987dbcf00aaff9b94a4f0 Mon Sep 17 00:00:00 2001 From: Yz Date: Sat, 27 Nov 2021 23:57:03 +0800 Subject: [PATCH] feat(sqlgen): allow any type of value for prepared mode --- sqlgen/expression_sql_generator.go | 7 +++++++ sqlgen/expression_sql_generator_test.go | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sqlgen/expression_sql_generator.go b/sqlgen/expression_sql_generator.go index 82ce15c5..fdc02893 100644 --- a/sqlgen/expression_sql_generator.go +++ b/sqlgen/expression_sql_generator.go @@ -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)) } } diff --git a/sqlgen/expression_sql_generator_test.go b/sqlgen/expression_sql_generator_test.go index ed75e12f..e5c057eb 100644 --- a/sqlgen/expression_sql_generator_test.go +++ b/sqlgen/expression_sql_generator_test.go @@ -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{}}}, ) }