Fix linter errors.
This commit is contained in:
parent
65e05021bc
commit
1cc463477d
4 changed files with 30 additions and 21 deletions
|
|
@ -31,5 +31,12 @@ func TestArgToString(t *testing.T) {
|
||||||
time, err := time.Parse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Jan 2 15:04:05 -0700 MST 2006")
|
time, err := time.Parse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Jan 2 15:04:05 -0700 MST 2006")
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Equal(t, argToString(time), "'2006-01-02 15:04:05-07:00'")
|
assert.Equal(t, argToString(time), "'2006-01-02 15:04:05-07:00'")
|
||||||
assert.Equal(t, argToString(map[string]bool{}), "[Unsupported type]")
|
|
||||||
|
func() {
|
||||||
|
defer func() {
|
||||||
|
assert.Equal(t, recover().(string), "jet: map[string]bool type can not be used as SQL query parameter")
|
||||||
|
}()
|
||||||
|
|
||||||
|
argToString(map[string]bool{})
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@ package jet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"github.com/go-jet/jet/internal/3rdparty/pq"
|
"github.com/go-jet/jet/internal/3rdparty/pq"
|
||||||
"github.com/go-jet/jet/internal/utils"
|
"github.com/go-jet/jet/internal/utils"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -176,7 +178,7 @@ func argToString(value interface{}) string {
|
||||||
case time.Time:
|
case time.Time:
|
||||||
return stringQuote(string(pq.FormatTimestamp(bindVal)))
|
return stringQuote(string(pq.FormatTimestamp(bindVal)))
|
||||||
default:
|
default:
|
||||||
return "[Unsupported type]"
|
panic(fmt.Sprintf("jet: %s type can not be used as SQL query parameter", reflect.TypeOf(value).String()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,13 @@ var Dialect = newDialect()
|
||||||
func newDialect() jet.Dialect {
|
func newDialect() jet.Dialect {
|
||||||
|
|
||||||
operatorSerializeOverrides := map[string]jet.SerializeOverride{}
|
operatorSerializeOverrides := map[string]jet.SerializeOverride{}
|
||||||
operatorSerializeOverrides[jet.StringRegexpLikeOperator] = mysql_REGEXP_LIKE_operator
|
operatorSerializeOverrides[jet.StringRegexpLikeOperator] = mysqlREGEXPLIKEoperator
|
||||||
operatorSerializeOverrides[jet.StringNotRegexpLikeOperator] = mysql_NOT_REGEXP_LIKE_operator
|
operatorSerializeOverrides[jet.StringNotRegexpLikeOperator] = mysqlNOTREGEXPLIKEoperator
|
||||||
operatorSerializeOverrides["IS DISTINCT FROM"] = mysql_IS_DISTINCT_FROM
|
operatorSerializeOverrides["IS DISTINCT FROM"] = mysqlISDISTINCTFROM
|
||||||
operatorSerializeOverrides["IS NOT DISTINCT FROM"] = mysql_IS_NOT_DISTINCT_FROM
|
operatorSerializeOverrides["IS NOT DISTINCT FROM"] = mysqlISNOTDISTINCTFROM
|
||||||
operatorSerializeOverrides["/"] = mysql_DIVISION
|
operatorSerializeOverrides["/"] = mysqlDivision
|
||||||
operatorSerializeOverrides["#"] = mysql_BIT_XOR
|
operatorSerializeOverrides["#"] = mysqlBitXor
|
||||||
operatorSerializeOverrides[jet.StringConcatOperator] = mysql_CONCAT_operator
|
operatorSerializeOverrides[jet.StringConcatOperator] = mysqlCONCAToperator
|
||||||
|
|
||||||
mySQLDialectParams := jet.DialectParams{
|
mySQLDialectParams := jet.DialectParams{
|
||||||
Name: "MySQL",
|
Name: "MySQL",
|
||||||
|
|
@ -32,7 +32,7 @@ func newDialect() jet.Dialect {
|
||||||
return jet.NewDialect(mySQLDialectParams)
|
return jet.NewDialect(mySQLDialectParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mysql_BIT_XOR(expressions ...jet.Expression) jet.SerializeFunc {
|
func mysqlBitXor(expressions ...jet.Expression) jet.SerializeFunc {
|
||||||
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
||||||
if len(expressions) < 2 {
|
if len(expressions) < 2 {
|
||||||
panic("jet: invalid number of expressions for operator XOR")
|
panic("jet: invalid number of expressions for operator XOR")
|
||||||
|
|
@ -49,7 +49,7 @@ func mysql_BIT_XOR(expressions ...jet.Expression) jet.SerializeFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mysql_CONCAT_operator(expressions ...jet.Expression) jet.SerializeFunc {
|
func mysqlCONCAToperator(expressions ...jet.Expression) jet.SerializeFunc {
|
||||||
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
||||||
if len(expressions) < 2 {
|
if len(expressions) < 2 {
|
||||||
panic("jet: invalid number of expressions for operator CONCAT")
|
panic("jet: invalid number of expressions for operator CONCAT")
|
||||||
|
|
@ -66,7 +66,7 @@ func mysql_CONCAT_operator(expressions ...jet.Expression) jet.SerializeFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mysql_DIVISION(expressions ...jet.Expression) jet.SerializeFunc {
|
func mysqlDivision(expressions ...jet.Expression) jet.SerializeFunc {
|
||||||
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
||||||
if len(expressions) < 2 {
|
if len(expressions) < 2 {
|
||||||
panic("jet: invalid number of expressions for operator DIV")
|
panic("jet: invalid number of expressions for operator DIV")
|
||||||
|
|
@ -90,7 +90,7 @@ func mysql_DIVISION(expressions ...jet.Expression) jet.SerializeFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mysql_IS_NOT_DISTINCT_FROM(expressions ...jet.Expression) jet.SerializeFunc {
|
func mysqlISNOTDISTINCTFROM(expressions ...jet.Expression) jet.SerializeFunc {
|
||||||
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
||||||
if len(expressions) < 2 {
|
if len(expressions) < 2 {
|
||||||
panic("jet: invalid number of expressions for operator")
|
panic("jet: invalid number of expressions for operator")
|
||||||
|
|
@ -102,15 +102,15 @@ func mysql_IS_NOT_DISTINCT_FROM(expressions ...jet.Expression) jet.SerializeFunc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mysql_IS_DISTINCT_FROM(expressions ...jet.Expression) jet.SerializeFunc {
|
func mysqlISDISTINCTFROM(expressions ...jet.Expression) jet.SerializeFunc {
|
||||||
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
||||||
out.WriteString("NOT(")
|
out.WriteString("NOT(")
|
||||||
mysql_IS_NOT_DISTINCT_FROM(expressions...)(statement, out, options...)
|
mysqlISNOTDISTINCTFROM(expressions...)(statement, out, options...)
|
||||||
out.WriteString(")")
|
out.WriteString(")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mysql_REGEXP_LIKE_operator(expressions ...jet.Expression) jet.SerializeFunc {
|
func mysqlREGEXPLIKEoperator(expressions ...jet.Expression) jet.SerializeFunc {
|
||||||
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
||||||
if len(expressions) < 2 {
|
if len(expressions) < 2 {
|
||||||
panic("jet: invalid number of expressions for operator")
|
panic("jet: invalid number of expressions for operator")
|
||||||
|
|
@ -136,7 +136,7 @@ func mysql_REGEXP_LIKE_operator(expressions ...jet.Expression) jet.SerializeFunc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mysql_NOT_REGEXP_LIKE_operator(expressions ...jet.Expression) jet.SerializeFunc {
|
func mysqlNOTREGEXPLIKEoperator(expressions ...jet.Expression) jet.SerializeFunc {
|
||||||
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
||||||
if len(expressions) < 2 {
|
if len(expressions) < 2 {
|
||||||
panic("jet: invalid number of expressions for operator")
|
panic("jet: invalid number of expressions for operator")
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ var Dialect = newDialect()
|
||||||
func newDialect() jet.Dialect {
|
func newDialect() jet.Dialect {
|
||||||
|
|
||||||
operatorSerializeOverrides := map[string]jet.SerializeOverride{}
|
operatorSerializeOverrides := map[string]jet.SerializeOverride{}
|
||||||
operatorSerializeOverrides[jet.StringRegexpLikeOperator] = postgres_REGEXP_LIKE_operator
|
operatorSerializeOverrides[jet.StringRegexpLikeOperator] = postgresREGEXPLIKEoperator
|
||||||
operatorSerializeOverrides[jet.StringNotRegexpLikeOperator] = postgres_NOT_REGEXP_LIKE_operator
|
operatorSerializeOverrides[jet.StringNotRegexpLikeOperator] = postgresNOTREGEXPLIKEoperator
|
||||||
operatorSerializeOverrides["CAST"] = postgresCAST
|
operatorSerializeOverrides["CAST"] = postgresCAST
|
||||||
|
|
||||||
dialectParams := jet.DialectParams{
|
dialectParams := jet.DialectParams{
|
||||||
|
|
@ -54,7 +54,7 @@ func postgresCAST(expressions ...jet.Expression) jet.SerializeFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func postgres_REGEXP_LIKE_operator(expressions ...jet.Expression) jet.SerializeFunc {
|
func postgresREGEXPLIKEoperator(expressions ...jet.Expression) jet.SerializeFunc {
|
||||||
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
||||||
if len(expressions) < 2 {
|
if len(expressions) < 2 {
|
||||||
panic("jet: invalid number of expressions for operator")
|
panic("jet: invalid number of expressions for operator")
|
||||||
|
|
@ -80,7 +80,7 @@ func postgres_REGEXP_LIKE_operator(expressions ...jet.Expression) jet.SerializeF
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func postgres_NOT_REGEXP_LIKE_operator(expressions ...jet.Expression) jet.SerializeFunc {
|
func postgresNOTREGEXPLIKEoperator(expressions ...jet.Expression) jet.SerializeFunc {
|
||||||
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
||||||
if len(expressions) < 2 {
|
if len(expressions) < 2 {
|
||||||
panic("jet: invalid number of expressions for operator")
|
panic("jet: invalid number of expressions for operator")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue