diff options
| author | 2021-10-24 13:14:37 +0200 | |
|---|---|---|
| committer | 2021-10-24 13:14:37 +0200 | |
| commit | 8b7c3507fe0c8f6e921ee2de2c170ef93eeb7275 (patch) | |
| tree | e79e3f5a59fb8942de79955bd26bf665be0acce8 /vendor/github.com/uptrace/bun/schema/scan.go | |
| parent | docs typo fix (#290) (diff) | |
| download | gotosocial-8b7c3507fe0c8f6e921ee2de2c170ef93eeb7275.tar.xz | |
upstep bun to v1.0.14 (#291)
Diffstat (limited to 'vendor/github.com/uptrace/bun/schema/scan.go')
| -rw-r--r-- | vendor/github.com/uptrace/bun/schema/scan.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/vendor/github.com/uptrace/bun/schema/scan.go b/vendor/github.com/uptrace/bun/schema/scan.go index 60ad27d53..30abcfc35 100644 --- a/vendor/github.com/uptrace/bun/schema/scan.go +++ b/vendor/github.com/uptrace/bun/schema/scan.go @@ -8,6 +8,7 @@ import ( "reflect" "strconv" "strings" + "sync" "time" "github.com/vmihailenco/msgpack/v5" @@ -52,6 +53,8 @@ func init() { } } +var scannerMap sync.Map + func FieldScanner(dialect Dialect, field *Field) ScannerFunc { if field.Tag.HasOption("msgpack") { return scanMsgpack @@ -65,10 +68,23 @@ func FieldScanner(dialect Dialect, field *Field) ScannerFunc { return scanJSONIntoInterface } } - return dialect.Scanner(field.StructField.Type) + return Scanner(field.StructField.Type) } func Scanner(typ reflect.Type) ScannerFunc { + if v, ok := scannerMap.Load(typ); ok { + return v.(ScannerFunc) + } + + fn := scanner(typ) + + if v, ok := scannerMap.LoadOrStore(typ, fn); ok { + return v.(ScannerFunc) + } + return fn +} + +func scanner(typ reflect.Type) ScannerFunc { kind := typ.Kind() if kind == reflect.Ptr { |
