diff options
Diffstat (limited to 'vendor/github.com/uptrace/bun/dialect')
6 files changed, 94 insertions, 14 deletions
diff --git a/vendor/github.com/uptrace/bun/dialect/pgdialect/array.go b/vendor/github.com/uptrace/bun/dialect/pgdialect/array.go index 058b9f2fb..b20c20434 100644 --- a/vendor/github.com/uptrace/bun/dialect/pgdialect/array.go +++ b/vendor/github.com/uptrace/bun/dialect/pgdialect/array.go @@ -142,6 +142,10 @@ func (d *Dialect) arrayElemAppender(typ reflect.Type) schema.AppenderFunc { if typ.Implements(driverValuerType) { return arrayAppendDriverValue } + if typ == timeType { + return appendTimeElemValue + } + switch typ.Kind() { case reflect.String: return appendStringElemValue @@ -149,10 +153,20 @@ func (d *Dialect) arrayElemAppender(typ reflect.Type) schema.AppenderFunc { if typ.Elem().Kind() == reflect.Uint8 { return appendBytesElemValue } + case reflect.Ptr: + return schema.PtrAppender(d.arrayElemAppender(typ.Elem())) } return schema.Appender(d, typ) } +func appendTimeElemValue(fmter schema.Formatter, b []byte, v reflect.Value) []byte { + ts := v.Convert(timeType).Interface().(time.Time) + + b = append(b, '"') + b = appendTime(b, ts) + return append(b, '"') +} + func appendStringElemValue(fmter schema.Formatter, b []byte, v reflect.Value) []byte { return appendStringElem(b, v.String()) } diff --git a/vendor/github.com/uptrace/bun/dialect/pgdialect/array_parser.go b/vendor/github.com/uptrace/bun/dialect/pgdialect/array_parser.go index 462f8d91d..56db9fd07 100644 --- a/vendor/github.com/uptrace/bun/dialect/pgdialect/array_parser.go +++ b/vendor/github.com/uptrace/bun/dialect/pgdialect/array_parser.go @@ -11,15 +11,23 @@ type arrayParser struct { elem []byte err error + + isJson bool } func newArrayParser(b []byte) *arrayParser { p := new(arrayParser) - if len(b) < 2 || b[0] != '{' || b[len(b)-1] != '}' { + if b[0] == 'n' { + p.p.Reset(nil) + return p + } + + if len(b) < 2 || (b[0] != '{' && b[0] != '[') || (b[len(b)-1] != '}' && b[len(b)-1] != ']') { p.err = fmt.Errorf("pgdialect: can't parse array: %q", b) return p } + p.isJson = b[0] == '[' p.p.Reset(b[1 : len(b)-1]) return p @@ -51,7 +59,7 @@ func (p *arrayParser) readNext() error { } switch ch { - case '}': + case '}', ']': return io.EOF case '"': b, err := p.p.ReadSubstring(ch) @@ -78,16 +86,34 @@ func (p *arrayParser) readNext() error { p.elem = rng return nil default: - lit := p.p.ReadLiteral(ch) - if bytes.Equal(lit, []byte("NULL")) { - lit = nil - } - - if p.p.Peek() == ',' { - p.p.Advance() + if ch == '{' && p.isJson { + json, err := p.p.ReadJSON() + if err != nil { + return err + } + + for { + if p.p.Peek() == ',' || p.p.Peek() == ' ' { + p.p.Advance() + } else { + break + } + } + + p.elem = json + return nil + } else { + lit := p.p.ReadLiteral(ch) + if bytes.Equal(lit, []byte("NULL")) { + lit = nil + } + + if p.p.Peek() == ',' { + p.p.Advance() + } + + p.elem = lit + return nil } - - p.elem = lit - return nil } } diff --git a/vendor/github.com/uptrace/bun/dialect/pgdialect/parser.go b/vendor/github.com/uptrace/bun/dialect/pgdialect/parser.go index 08f4727db..c0a6299d9 100644 --- a/vendor/github.com/uptrace/bun/dialect/pgdialect/parser.go +++ b/vendor/github.com/uptrace/bun/dialect/pgdialect/parser.go @@ -105,3 +105,39 @@ func (p *pgparser) ReadRange(ch byte) ([]byte, error) { return p.buf, nil } + +func (p *pgparser) ReadJSON() ([]byte, error) { + p.Unread() + + c, err := p.ReadByte() + if err != nil { + return nil, err + } + + p.buf = p.buf[:0] + + depth := 0 + for { + switch c { + case '{': + depth++ + case '}': + depth-- + } + + p.buf = append(p.buf, c) + + if depth == 0 { + break + } + + next, err := p.ReadByte() + if err != nil { + return nil, err + } + + c = next + } + + return p.buf, nil +} diff --git a/vendor/github.com/uptrace/bun/dialect/pgdialect/sqltype.go b/vendor/github.com/uptrace/bun/dialect/pgdialect/sqltype.go index 99075cbc1..121a3d691 100644 --- a/vendor/github.com/uptrace/bun/dialect/pgdialect/sqltype.go +++ b/vendor/github.com/uptrace/bun/dialect/pgdialect/sqltype.go @@ -86,6 +86,10 @@ func fieldSQLType(field *schema.Field) string { } func sqlType(typ reflect.Type) string { + if typ.Kind() == reflect.Ptr { + typ = typ.Elem() + } + switch typ { case nullStringType: // typ.Kind() == reflect.Struct, test for exact match return sqltype.VarChar diff --git a/vendor/github.com/uptrace/bun/dialect/pgdialect/version.go b/vendor/github.com/uptrace/bun/dialect/pgdialect/version.go index 4e0c5ef36..59d0bc649 100644 --- a/vendor/github.com/uptrace/bun/dialect/pgdialect/version.go +++ b/vendor/github.com/uptrace/bun/dialect/pgdialect/version.go @@ -2,5 +2,5 @@ package pgdialect // Version is the current release version. func Version() string { - return "1.2.9" + return "1.2.10" } diff --git a/vendor/github.com/uptrace/bun/dialect/sqlitedialect/version.go b/vendor/github.com/uptrace/bun/dialect/sqlitedialect/version.go index e42267b8a..c7211d1bd 100644 --- a/vendor/github.com/uptrace/bun/dialect/sqlitedialect/version.go +++ b/vendor/github.com/uptrace/bun/dialect/sqlitedialect/version.go @@ -2,5 +2,5 @@ package sqlitedialect // Version is the current release version. func Version() string { - return "1.2.9" + return "1.2.10" } |
