Add support for blob expressions.

This commit is contained in:
go-jet 2025-02-28 18:23:15 +01:00
parent 26e478dc7e
commit c94216ab0e
37 changed files with 1296 additions and 81 deletions

View file

@ -1,6 +1,7 @@
package postgres
import (
"encoding/hex"
"fmt"
"strconv"
@ -26,7 +27,8 @@ func newDialect() jet.Dialect {
ArgumentPlaceholder: func(ord int) string {
return "$" + strconv.Itoa(ord)
},
ReservedWords: reservedWords,
ArgumentToString: argumentToString,
ReservedWords: reservedWords,
ValuesDefaultColumnName: func(index int) string {
return fmt.Sprintf("column%d", index+1)
},
@ -35,6 +37,15 @@ func newDialect() jet.Dialect {
return jet.NewDialect(dialectParams)
}
func argumentToString(value any) (string, bool) {
switch bindVal := value.(type) {
case []byte:
return fmt.Sprintf("'\\x%s'", hex.EncodeToString(bindVal)), true
}
return "", false
}
func postgresCAST(expressions ...jet.Serializer) jet.SerializerFunc {
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
if len(expressions) < 2 {