summaryrefslogtreecommitdiff
path: root/vendor/github.com/uptrace/bun/schema/dialect.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-10-24 13:14:37 +0200
committerLibravatar GitHub <noreply@github.com>2021-10-24 13:14:37 +0200
commit8b7c3507fe0c8f6e921ee2de2c170ef93eeb7275 (patch)
treee79e3f5a59fb8942de79955bd26bf665be0acce8 /vendor/github.com/uptrace/bun/schema/dialect.go
parentdocs typo fix (#290) (diff)
downloadgotosocial-8b7c3507fe0c8f6e921ee2de2c170ef93eeb7275.tar.xz
upstep bun to v1.0.14 (#291)
Diffstat (limited to 'vendor/github.com/uptrace/bun/schema/dialect.go')
-rw-r--r--vendor/github.com/uptrace/bun/schema/dialect.go109
1 files changed, 66 insertions, 43 deletions
diff --git a/vendor/github.com/uptrace/bun/schema/dialect.go b/vendor/github.com/uptrace/bun/schema/dialect.go
index c50de715a..f015807dc 100644
--- a/vendor/github.com/uptrace/bun/schema/dialect.go
+++ b/vendor/github.com/uptrace/bun/schema/dialect.go
@@ -2,11 +2,12 @@ package schema
import (
"database/sql"
- "reflect"
- "sync"
+ "strconv"
+ "time"
"github.com/uptrace/bun/dialect"
"github.com/uptrace/bun/dialect/feature"
+ "github.com/uptrace/bun/internal/parser"
)
type Dialect interface {
@@ -19,20 +20,76 @@ type Dialect interface {
OnTable(table *Table)
IdentQuote() byte
- Append(fmter Formatter, b []byte, v interface{}) []byte
- Appender(typ reflect.Type) AppenderFunc
- FieldAppender(field *Field) AppenderFunc
- Scanner(typ reflect.Type) ScannerFunc
+
+ AppendUint32(b []byte, n uint32) []byte
+ AppendUint64(b []byte, n uint64) []byte
+ AppendTime(b []byte, tm time.Time) []byte
+ AppendBytes(b []byte, bs []byte) []byte
+ AppendJSON(b, jsonb []byte) []byte
+}
+
+//------------------------------------------------------------------------------
+
+type BaseDialect struct{}
+
+func (BaseDialect) AppendUint32(b []byte, n uint32) []byte {
+ return strconv.AppendUint(b, uint64(n), 10)
+}
+
+func (BaseDialect) AppendUint64(b []byte, n uint64) []byte {
+ return strconv.AppendUint(b, n, 10)
+}
+
+func (BaseDialect) AppendTime(b []byte, tm time.Time) []byte {
+ b = append(b, '\'')
+ b = tm.UTC().AppendFormat(b, "2006-01-02 15:04:05.999999-07:00")
+ b = append(b, '\'')
+ return b
+}
+
+func (BaseDialect) AppendBytes(b, bs []byte) []byte {
+ return dialect.AppendBytes(b, bs)
+}
+
+func (BaseDialect) AppendJSON(b, jsonb []byte) []byte {
+ b = append(b, '\'')
+
+ p := parser.New(jsonb)
+ for p.Valid() {
+ c := p.Read()
+ switch c {
+ case '"':
+ b = append(b, '"')
+ case '\'':
+ b = append(b, "''"...)
+ case '\000':
+ continue
+ case '\\':
+ if p.SkipBytes([]byte("u0000")) {
+ b = append(b, `\\u0000`...)
+ } else {
+ b = append(b, '\\')
+ if p.Valid() {
+ b = append(b, p.Read())
+ }
+ }
+ default:
+ b = append(b, c)
+ }
+ }
+
+ b = append(b, '\'')
+
+ return b
}
//------------------------------------------------------------------------------
type nopDialect struct {
+ BaseDialect
+
tables *Tables
features feature.Feature
-
- appenderMap sync.Map
- scannerMap sync.Map
}
func newNopDialect() *nopDialect {
@@ -63,37 +120,3 @@ func (d *nopDialect) OnTable(table *Table) {}
func (d *nopDialect) IdentQuote() byte {
return '"'
}
-
-func (d *nopDialect) Append(fmter Formatter, b []byte, v interface{}) []byte {
- return Append(fmter, b, v, nil)
-}
-
-func (d *nopDialect) Appender(typ reflect.Type) AppenderFunc {
- if v, ok := d.appenderMap.Load(typ); ok {
- return v.(AppenderFunc)
- }
-
- fn := Appender(typ, nil)
-
- if v, ok := d.appenderMap.LoadOrStore(typ, fn); ok {
- return v.(AppenderFunc)
- }
- return fn
-}
-
-func (d *nopDialect) FieldAppender(field *Field) AppenderFunc {
- return FieldAppender(d, field)
-}
-
-func (d *nopDialect) Scanner(typ reflect.Type) ScannerFunc {
- if v, ok := d.scannerMap.Load(typ); ok {
- return v.(ScannerFunc)
- }
-
- fn := Scanner(typ)
-
- if v, ok := d.scannerMap.LoadOrStore(typ, fn); ok {
- return v.(ScannerFunc)
- }
- return fn
-}