@@ -3,6 +3,7 @@ package pgdialect
33import (
44 "database/sql"
55 "fmt"
6+ "strconv"
67 "strings"
78
89 "github.com/uptrace/bun"
@@ -25,8 +26,9 @@ func init() {
2526type Dialect struct {
2627 schema.BaseDialect
2728
28- tables * schema.Tables
29- features feature.Feature
29+ tables * schema.Tables
30+ features feature.Feature
31+ uintAsInt bool
3032}
3133
3234var _ schema.Dialect = (* Dialect )(nil )
@@ -71,6 +73,12 @@ func WithoutFeature(other feature.Feature) DialectOption {
7173 }
7274}
7375
76+ func WithAppendUintAsInt (on bool ) DialectOption {
77+ return func (d * Dialect ) {
78+ d .uintAsInt = on
79+ }
80+ }
81+
7482func (d * Dialect ) Init (* sql.DB ) {}
7583
7684func (d * Dialect ) Name () dialect.Name {
@@ -128,6 +136,20 @@ func (d *Dialect) IdentQuote() byte {
128136 return '"'
129137}
130138
139+ func (d * Dialect ) AppendUint32 (b []byte , n uint32 ) []byte {
140+ if d .uintAsInt {
141+ return strconv .AppendInt (b , int64 (int32 (n )), 10 )
142+ }
143+ return strconv .AppendUint (b , uint64 (n ), 10 )
144+ }
145+
146+ func (d * Dialect ) AppendUint64 (b []byte , n uint64 ) []byte {
147+ if d .uintAsInt {
148+ return strconv .AppendInt (b , int64 (n ), 10 )
149+ }
150+ return strconv .AppendUint (b , n , 10 )
151+ }
152+
131153func (d * Dialect ) AppendSequence (b []byte , _ * schema.Table , _ * schema.Field ) []byte {
132154 return appendGeneratedAsIdentity (b )
133155}
0 commit comments