summaryrefslogtreecommitdiff
path: root/vendor/github.com/uptrace/bun/dialect/pgdialect/array_parser.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2025-03-03 10:42:05 +0000
committerLibravatar GitHub <noreply@github.com>2025-03-03 10:42:05 +0000
commit67a2b3650c5f586431c8559bc9b609699de8431d (patch)
treef4a269939f7f175277a92aaa33bf58e652d4e276 /vendor/github.com/uptrace/bun/dialect/pgdialect/array_parser.go
parent[chore]: Bump github.com/prometheus/client_golang from 1.20.5 to 1.21.0 (#3860) (diff)
downloadgotosocial-67a2b3650c5f586431c8559bc9b609699de8431d.tar.xz
bumps our uptrace/bun dependencies to v1.2.10 (#3865)
Diffstat (limited to 'vendor/github.com/uptrace/bun/dialect/pgdialect/array_parser.go')
-rw-r--r--vendor/github.com/uptrace/bun/dialect/pgdialect/array_parser.go50
1 files changed, 38 insertions, 12 deletions
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
}
}