mirror of https://github.com/jackc/pgx.git
Add comments to explain the use of reflection after type assertion.
Removes one local variable, which is used twice only in an error.non-blocking
parent
b90570feb5
commit
ec14212d30
|
@ -29,6 +29,7 @@ func (dst *ACLItemArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []string:
|
||||
|
@ -82,6 +83,9 @@ func (dst *ACLItemArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = ACLItemArray{Status: Null}
|
||||
|
@ -187,6 +191,7 @@ func (src *ACLItemArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]string:
|
||||
|
@ -210,6 +215,9 @@ func (src *ACLItemArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -249,9 +257,8 @@ func (src *ACLItemArray) assignToRecursive(value reflect.Value, index, dimension
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ func (dst *BoolArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []bool:
|
||||
|
@ -84,6 +85,9 @@ func (dst *BoolArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = BoolArray{Status: Null}
|
||||
|
@ -189,6 +193,7 @@ func (src *BoolArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]bool:
|
||||
|
@ -212,6 +217,9 @@ func (src *BoolArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -251,9 +259,8 @@ func (src *BoolArray) assignToRecursive(value reflect.Value, index, dimension in
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ func (dst *BPCharArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []string:
|
||||
|
@ -84,6 +85,9 @@ func (dst *BPCharArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = BPCharArray{Status: Null}
|
||||
|
@ -189,6 +193,7 @@ func (src *BPCharArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]string:
|
||||
|
@ -212,6 +217,9 @@ func (src *BPCharArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -251,9 +259,8 @@ func (src *BPCharArray) assignToRecursive(value reflect.Value, index, dimension
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ func (dst *ByteaArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case [][]byte:
|
||||
|
@ -65,6 +66,9 @@ func (dst *ByteaArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = ByteaArray{Status: Null}
|
||||
|
@ -170,6 +174,7 @@ func (src *ByteaArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[][]byte:
|
||||
|
@ -184,6 +189,9 @@ func (src *ByteaArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -223,9 +231,8 @@ func (src *ByteaArray) assignToRecursive(value reflect.Value, index, dimension i
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -32,6 +32,7 @@ func (dst *CIDRArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []*net.IPNet:
|
||||
|
@ -104,6 +105,9 @@ func (dst *CIDRArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = CIDRArray{Status: Null}
|
||||
|
@ -209,6 +213,7 @@ func (src *CIDRArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]*net.IPNet:
|
||||
|
@ -241,6 +246,9 @@ func (src *CIDRArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -280,9 +288,8 @@ func (src *CIDRArray) assignToRecursive(value reflect.Value, index, dimension in
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -32,6 +32,7 @@ func (dst *DateArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []time.Time:
|
||||
|
@ -85,6 +86,9 @@ func (dst *DateArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = DateArray{Status: Null}
|
||||
|
@ -190,6 +194,7 @@ func (src *DateArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]time.Time:
|
||||
|
@ -213,6 +218,9 @@ func (src *DateArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -252,9 +260,8 @@ func (src *DateArray) assignToRecursive(value reflect.Value, index, dimension in
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -29,6 +29,7 @@ func (dst *EnumArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []string:
|
||||
|
@ -82,6 +83,9 @@ func (dst *EnumArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = EnumArray{Status: Null}
|
||||
|
@ -187,6 +191,7 @@ func (src *EnumArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]string:
|
||||
|
@ -210,6 +215,9 @@ func (src *EnumArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -249,9 +257,8 @@ func (src *EnumArray) assignToRecursive(value reflect.Value, index, dimension in
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ func (dst *Float4Array) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []float32:
|
||||
|
@ -84,6 +85,9 @@ func (dst *Float4Array) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = Float4Array{Status: Null}
|
||||
|
@ -189,6 +193,7 @@ func (src *Float4Array) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]float32:
|
||||
|
@ -212,6 +217,9 @@ func (src *Float4Array) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -251,9 +259,8 @@ func (src *Float4Array) assignToRecursive(value reflect.Value, index, dimension
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ func (dst *Float8Array) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []float64:
|
||||
|
@ -84,6 +85,9 @@ func (dst *Float8Array) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = Float8Array{Status: Null}
|
||||
|
@ -189,6 +193,7 @@ func (src *Float8Array) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]float64:
|
||||
|
@ -212,6 +217,9 @@ func (src *Float8Array) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -251,9 +259,8 @@ func (src *Float8Array) assignToRecursive(value reflect.Value, index, dimension
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ func (dst *HstoreArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []map[string]string:
|
||||
|
@ -65,6 +66,9 @@ func (dst *HstoreArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = HstoreArray{Status: Null}
|
||||
|
@ -170,6 +174,7 @@ func (src *HstoreArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]map[string]string:
|
||||
|
@ -184,6 +189,9 @@ func (src *HstoreArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -223,9 +231,8 @@ func (src *HstoreArray) assignToRecursive(value reflect.Value, index, dimension
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -32,6 +32,7 @@ func (dst *InetArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []*net.IPNet:
|
||||
|
@ -104,6 +105,9 @@ func (dst *InetArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = InetArray{Status: Null}
|
||||
|
@ -209,6 +213,7 @@ func (src *InetArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]*net.IPNet:
|
||||
|
@ -241,6 +246,9 @@ func (src *InetArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -280,9 +288,8 @@ func (src *InetArray) assignToRecursive(value reflect.Value, index, dimension in
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ func (dst *Int2Array) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []int16:
|
||||
|
@ -350,6 +351,9 @@ func (dst *Int2Array) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = Int2Array{Status: Null}
|
||||
|
@ -455,6 +459,7 @@ func (src *Int2Array) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]int16:
|
||||
|
@ -604,6 +609,9 @@ func (src *Int2Array) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -643,9 +651,8 @@ func (src *Int2Array) assignToRecursive(value reflect.Value, index, dimension in
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ func (dst *Int4Array) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []int16:
|
||||
|
@ -350,6 +351,9 @@ func (dst *Int4Array) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = Int4Array{Status: Null}
|
||||
|
@ -455,6 +459,7 @@ func (src *Int4Array) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]int16:
|
||||
|
@ -604,6 +609,9 @@ func (src *Int4Array) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -643,9 +651,8 @@ func (src *Int4Array) assignToRecursive(value reflect.Value, index, dimension in
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ func (dst *Int8Array) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []int16:
|
||||
|
@ -350,6 +351,9 @@ func (dst *Int8Array) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = Int8Array{Status: Null}
|
||||
|
@ -455,6 +459,7 @@ func (src *Int8Array) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]int16:
|
||||
|
@ -604,6 +609,9 @@ func (src *Int8Array) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -643,9 +651,8 @@ func (src *Int8Array) assignToRecursive(value reflect.Value, index, dimension in
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ func (dst *JSONBArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []string:
|
||||
|
@ -65,6 +66,9 @@ func (dst *JSONBArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = JSONBArray{Status: Null}
|
||||
|
@ -170,6 +174,7 @@ func (src *JSONBArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]string:
|
||||
|
@ -184,6 +189,9 @@ func (src *JSONBArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -223,9 +231,8 @@ func (src *JSONBArray) assignToRecursive(value reflect.Value, index, dimension i
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -32,6 +32,7 @@ func (dst *MacaddrArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []net.HardwareAddr:
|
||||
|
@ -85,6 +86,9 @@ func (dst *MacaddrArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = MacaddrArray{Status: Null}
|
||||
|
@ -190,6 +194,7 @@ func (src *MacaddrArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]net.HardwareAddr:
|
||||
|
@ -213,6 +218,9 @@ func (src *MacaddrArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -252,9 +260,8 @@ func (src *MacaddrArray) assignToRecursive(value reflect.Value, index, dimension
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ func (dst *NumericArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []float32:
|
||||
|
@ -198,6 +199,9 @@ func (dst *NumericArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = NumericArray{Status: Null}
|
||||
|
@ -303,6 +307,7 @@ func (src *NumericArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]float32:
|
||||
|
@ -380,6 +385,9 @@ func (src *NumericArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -419,9 +427,8 @@ func (src *NumericArray) assignToRecursive(value reflect.Value, index, dimension
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ func (dst *TextArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []string:
|
||||
|
@ -84,6 +85,9 @@ func (dst *TextArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = TextArray{Status: Null}
|
||||
|
@ -189,6 +193,7 @@ func (src *TextArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]string:
|
||||
|
@ -212,6 +217,9 @@ func (src *TextArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -251,9 +259,8 @@ func (src *TextArray) assignToRecursive(value reflect.Value, index, dimension in
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -32,6 +32,7 @@ func (dst *TimestampArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []time.Time:
|
||||
|
@ -85,6 +86,9 @@ func (dst *TimestampArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = TimestampArray{Status: Null}
|
||||
|
@ -190,6 +194,7 @@ func (src *TimestampArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]time.Time:
|
||||
|
@ -213,6 +218,9 @@ func (src *TimestampArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -252,9 +260,8 @@ func (src *TimestampArray) assignToRecursive(value reflect.Value, index, dimensi
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -32,6 +32,7 @@ func (dst *TimestamptzArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []time.Time:
|
||||
|
@ -85,6 +86,9 @@ func (dst *TimestamptzArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = TimestamptzArray{Status: Null}
|
||||
|
@ -190,6 +194,7 @@ func (src *TimestamptzArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]time.Time:
|
||||
|
@ -213,6 +218,9 @@ func (src *TimestamptzArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -252,9 +260,8 @@ func (src *TimestamptzArray) assignToRecursive(value reflect.Value, index, dimen
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ func (dst *TstzrangeArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []Tstzrange:
|
||||
|
@ -46,6 +47,9 @@ func (dst *TstzrangeArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = TstzrangeArray{Status: Null}
|
||||
|
@ -151,6 +155,7 @@ func (src *TstzrangeArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]Tstzrange:
|
||||
|
@ -165,6 +170,9 @@ func (src *TstzrangeArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -204,9 +212,8 @@ func (src *TstzrangeArray) assignToRecursive(value reflect.Value, index, dimensi
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -30,6 +30,7 @@ func (dst *<%= pgtype_array_type %>) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
<% go_array_types.split(",").each do |t| %>
|
||||
<% if t != "[]#{pgtype_element_type}" %>
|
||||
|
@ -66,6 +67,9 @@ func (dst *<%= pgtype_array_type %>) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = <%= pgtype_array_type %>{Status: Null}
|
||||
|
@ -171,6 +175,7 @@ func (src *<%= pgtype_array_type %>) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1{
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
<% go_array_types.split(",").each do |t| %>
|
||||
case *<%= t %>:
|
||||
|
@ -185,6 +190,9 @@ func (src *<%= pgtype_array_type %>) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -224,9 +232,8 @@ func (src *<%= pgtype_array_type %>) assignToRecursive(value reflect.Value, inde
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ func (dst *UUIDArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case [][16]byte:
|
||||
|
@ -122,6 +123,9 @@ func (dst *UUIDArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = UUIDArray{Status: Null}
|
||||
|
@ -227,6 +231,7 @@ func (src *UUIDArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[][16]byte:
|
||||
|
@ -268,6 +273,9 @@ func (src *UUIDArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -307,9 +315,8 @@ func (src *UUIDArray) assignToRecursive(value reflect.Value, index, dimension in
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ func (dst *VarcharArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Attempt to match to select common types:
|
||||
switch value := src.(type) {
|
||||
|
||||
case []string:
|
||||
|
@ -84,6 +85,9 @@ func (dst *VarcharArray) Set(src interface{}) error {
|
|||
}
|
||||
}
|
||||
default:
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
reflectedValue := reflect.ValueOf(src)
|
||||
if !reflectedValue.IsValid() || reflectedValue.IsZero() {
|
||||
*dst = VarcharArray{Status: Null}
|
||||
|
@ -189,6 +193,7 @@ func (src *VarcharArray) AssignTo(dst interface{}) error {
|
|||
switch src.Status {
|
||||
case Present:
|
||||
if len(src.Dimensions) == 1 {
|
||||
// Attempt to match to select common types:
|
||||
switch v := dst.(type) {
|
||||
|
||||
case *[]string:
|
||||
|
@ -212,6 +217,9 @@ func (src *VarcharArray) AssignTo(dst interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback to reflection if an optimised match was not found.
|
||||
// The reflection is necessary for arrays and multidimensional slices,
|
||||
// but it comes with a 20-50% performance penalty for large arrays/slices
|
||||
value := reflect.ValueOf(dst)
|
||||
if value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
|
@ -251,9 +259,8 @@ func (src *VarcharArray) assignToRecursive(value reflect.Value, index, dimension
|
|||
length := int(src.Dimensions[dimension].Length)
|
||||
if reflect.Array == kind {
|
||||
typ := value.Type()
|
||||
typLen := typ.Len()
|
||||
if typLen != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen)
|
||||
if typ.Len() != length {
|
||||
return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len())
|
||||
}
|
||||
value.Set(reflect.New(typ).Elem())
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue