github.com/octohelm/storage@v0.0.0-20240516030302-1ac2cc1ea347/pkg/datatypes/convert.go (about) 1 package datatypes 2 3 import ( 4 "database/sql" 5 "database/sql/driver" 6 7 "github.com/octohelm/x/encoding" 8 ) 9 10 func Scan(b []byte, v any) error { 11 if scanner, ok := v.(sql.Scanner); ok { 12 return scanner.Scan(b) 13 } 14 return encoding.UnmarshalText(v, b) 15 } 16 17 func Value(v any) (driver.Value, error) { 18 if valuer, ok := v.(driver.Valuer); ok { 19 return valuer.Value() 20 } 21 return driver.DefaultParameterConverter.ConvertValue(v) 22 }