diff options
Diffstat (limited to 'vendor/github.com/uptrace/bun/schema/scan.go')
-rw-r--r-- | vendor/github.com/uptrace/bun/schema/scan.go | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/vendor/github.com/uptrace/bun/schema/scan.go b/vendor/github.com/uptrace/bun/schema/scan.go index 85ba62a01..238fde217 100644 --- a/vendor/github.com/uptrace/bun/schema/scan.go +++ b/vendor/github.com/uptrace/bun/schema/scan.go @@ -77,6 +77,17 @@ func Scanner(typ reflect.Type) ScannerFunc { } } + switch typ { + case timeType: + return scanTime + case ipType: + return scanIP + case ipNetType: + return scanIPNet + case jsonRawMessageType: + return scanBytes + } + if typ.Implements(scannerType) { return scanScanner } @@ -88,17 +99,8 @@ func Scanner(typ reflect.Type) ScannerFunc { } } - switch typ { - case timeType: - return scanTime - case ipType: - return scanIP - case ipNetType: - return scanIPNet - case bytesType: + if typ.Kind() == reflect.Slice && typ.Elem().Kind() == reflect.Uint8 { return scanBytes - case jsonRawMessageType: - return scanJSONRawMessage } return scanners[kind] @@ -218,7 +220,10 @@ func scanBytes(dest reflect.Value, src interface{}) error { dest.SetBytes([]byte(src)) return nil case []byte: - dest.SetBytes(src) + clone := make([]byte, len(src)) + copy(clone, src) + + dest.SetBytes(clone) return nil } return fmt.Errorf("bun: can't scan %#v into %s", src, dest.Type()) @@ -345,21 +350,6 @@ func scanIPNet(dest reflect.Value, src interface{}) error { return nil } -func scanJSONRawMessage(dest reflect.Value, src interface{}) error { - if src == nil { - dest.SetBytes(nil) - return nil - } - - b, err := toBytes(src) - if err != nil { - return err - } - - dest.SetBytes(b) - return nil -} - func addrScanner(fn ScannerFunc) ScannerFunc { return func(dest reflect.Value, src interface{}) error { if !dest.CanAddr() { |