Skip to content

Commit

Permalink
fix: addng dialect override for append-bool (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sten Roger Sandvik committed Oct 27, 2022
1 parent bae46b4 commit 338f2f0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions dialect/mssqldialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"log"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -116,6 +117,16 @@ func (*Dialect) AppendBytes(b, bs []byte) []byte {
return b
}

func (*Dialect) AppendBool(b []byte, v bool) []byte {
num := 0

if v {
num = 1
}

return strconv.AppendUint(b, uint64(num), 10)
}

func sqlType(field *schema.Field) string {
switch field.DiscoveredSQLType {
case sqltype.VarChar:
Expand Down
2 changes: 1 addition & 1 deletion schema/append_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func PtrAppender(fn AppenderFunc) AppenderFunc {
}

func AppendBoolValue(fmter Formatter, b []byte, v reflect.Value) []byte {
return dialect.AppendBool(b, v.Bool())
return fmter.Dialect().AppendBool(b, v.Bool())
}

func AppendIntValue(fmter Formatter, b []byte, v reflect.Value) []byte {
Expand Down
5 changes: 5 additions & 0 deletions schema/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Dialect interface {
AppendString(b []byte, s string) []byte
AppendBytes(b []byte, bs []byte) []byte
AppendJSON(b, jsonb []byte) []byte
AppendBool(b []byte, v bool) []byte
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -126,6 +127,10 @@ func (BaseDialect) AppendJSON(b, jsonb []byte) []byte {
return b
}

func (BaseDialect) AppendBool(b []byte, v bool) []byte {
return dialect.AppendBool(b, v)
}

//------------------------------------------------------------------------------

type nopDialect struct {
Expand Down

0 comments on commit 338f2f0

Please sign in to comment.