Generate UUIDArray from template

- Fix error in Set
- Specifically handle untyped nil
pull/315/head
Jack Christensen 2017-08-29 14:33:25 -05:00
parent 1e36edf4b0
commit 4e26b04d6e
20 changed files with 129 additions and 19 deletions

View File

@ -13,6 +13,12 @@ type ACLItemArray struct {
}
func (dst *ACLItemArray) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = ACLItemArray{Status: Null}
return nil
}
switch value := src.(type) {
case []string:
@ -38,7 +44,7 @@ func (dst *ACLItemArray) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to ACLItem", value)
return errors.Errorf("cannot convert %v to ACLItemArray", value)
}
return nil

View File

@ -15,6 +15,12 @@ type BoolArray struct {
}
func (dst *BoolArray) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = BoolArray{Status: Null}
return nil
}
switch value := src.(type) {
case []bool:
@ -40,7 +46,7 @@ func (dst *BoolArray) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to Bool", value)
return errors.Errorf("cannot convert %v to BoolArray", value)
}
return nil

View File

@ -15,6 +15,12 @@ type ByteaArray struct {
}
func (dst *ByteaArray) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = ByteaArray{Status: Null}
return nil
}
switch value := src.(type) {
case [][]byte:
@ -40,7 +46,7 @@ func (dst *ByteaArray) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to Bytea", value)
return errors.Errorf("cannot convert %v to ByteaArray", value)
}
return nil

View File

@ -16,6 +16,12 @@ type CIDRArray struct {
}
func (dst *CIDRArray) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = CIDRArray{Status: Null}
return nil
}
switch value := src.(type) {
case []*net.IPNet:
@ -60,7 +66,7 @@ func (dst *CIDRArray) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to CIDR", value)
return errors.Errorf("cannot convert %v to CIDRArray", value)
}
return nil

View File

@ -16,6 +16,12 @@ type DateArray struct {
}
func (dst *DateArray) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = DateArray{Status: Null}
return nil
}
switch value := src.(type) {
case []time.Time:
@ -41,7 +47,7 @@ func (dst *DateArray) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to Date", value)
return errors.Errorf("cannot convert %v to DateArray", value)
}
return nil

View File

@ -15,6 +15,12 @@ type Float4Array struct {
}
func (dst *Float4Array) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = Float4Array{Status: Null}
return nil
}
switch value := src.(type) {
case []float32:
@ -40,7 +46,7 @@ func (dst *Float4Array) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to Float4", value)
return errors.Errorf("cannot convert %v to Float4Array", value)
}
return nil

View File

@ -15,6 +15,12 @@ type Float8Array struct {
}
func (dst *Float8Array) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = Float8Array{Status: Null}
return nil
}
switch value := src.(type) {
case []float64:
@ -40,7 +46,7 @@ func (dst *Float8Array) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to Float8", value)
return errors.Errorf("cannot convert %v to Float8Array", value)
}
return nil

View File

@ -15,6 +15,12 @@ type HstoreArray struct {
}
func (dst *HstoreArray) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = HstoreArray{Status: Null}
return nil
}
switch value := src.(type) {
case []map[string]string:
@ -40,7 +46,7 @@ func (dst *HstoreArray) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to Hstore", value)
return errors.Errorf("cannot convert %v to HstoreArray", value)
}
return nil

View File

@ -16,6 +16,12 @@ type InetArray struct {
}
func (dst *InetArray) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = InetArray{Status: Null}
return nil
}
switch value := src.(type) {
case []*net.IPNet:
@ -60,7 +66,7 @@ func (dst *InetArray) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to Inet", value)
return errors.Errorf("cannot convert %v to InetArray", value)
}
return nil

View File

@ -15,6 +15,12 @@ type Int2Array struct {
}
func (dst *Int2Array) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = Int2Array{Status: Null}
return nil
}
switch value := src.(type) {
case []int16:
@ -59,7 +65,7 @@ func (dst *Int2Array) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to Int2", value)
return errors.Errorf("cannot convert %v to Int2Array", value)
}
return nil

View File

@ -15,6 +15,12 @@ type Int4Array struct {
}
func (dst *Int4Array) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = Int4Array{Status: Null}
return nil
}
switch value := src.(type) {
case []int32:
@ -59,7 +65,7 @@ func (dst *Int4Array) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to Int4", value)
return errors.Errorf("cannot convert %v to Int4Array", value)
}
return nil

View File

@ -15,6 +15,12 @@ type Int8Array struct {
}
func (dst *Int8Array) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = Int8Array{Status: Null}
return nil
}
switch value := src.(type) {
case []int64:
@ -59,7 +65,7 @@ func (dst *Int8Array) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to Int8", value)
return errors.Errorf("cannot convert %v to Int8Array", value)
}
return nil

View File

@ -15,6 +15,12 @@ type NumericArray struct {
}
func (dst *NumericArray) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = NumericArray{Status: Null}
return nil
}
switch value := src.(type) {
case []float32:
@ -59,7 +65,7 @@ func (dst *NumericArray) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to Numeric", value)
return errors.Errorf("cannot convert %v to NumericArray", value)
}
return nil

View File

@ -15,6 +15,12 @@ type TextArray struct {
}
func (dst *TextArray) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = TextArray{Status: Null}
return nil
}
switch value := src.(type) {
case []string:
@ -40,7 +46,7 @@ func (dst *TextArray) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to Text", value)
return errors.Errorf("cannot convert %v to TextArray", value)
}
return nil

View File

@ -16,6 +16,12 @@ type TimestampArray struct {
}
func (dst *TimestampArray) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = TimestampArray{Status: Null}
return nil
}
switch value := src.(type) {
case []time.Time:
@ -41,7 +47,7 @@ func (dst *TimestampArray) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to Timestamp", value)
return errors.Errorf("cannot convert %v to TimestampArray", value)
}
return nil

View File

@ -16,6 +16,12 @@ type TimestamptzArray struct {
}
func (dst *TimestamptzArray) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = TimestamptzArray{Status: Null}
return nil
}
switch value := src.(type) {
case []time.Time:
@ -41,7 +47,7 @@ func (dst *TimestamptzArray) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to Timestamptz", value)
return errors.Errorf("cannot convert %v to TimestamptzArray", value)
}
return nil

View File

@ -15,6 +15,12 @@ type <%= pgtype_array_type %> struct {
}
func (dst *<%= pgtype_array_type %>) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = <%= pgtype_array_type %>{Status: Null}
return nil
}
switch value := src.(type) {
<% go_array_types.split(",").each do |t| %>
case <%= t %>:
@ -40,7 +46,7 @@ func (dst *<%= pgtype_array_type %>) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to <%= pgtype_element_type %>", value)
return errors.Errorf("cannot convert %v to <%= pgtype_array_type %>", value)
}
return nil

View File

@ -15,4 +15,5 @@ erb pgtype_array_type=ByteaArray pgtype_element_type=Bytea go_array_types=[][]by
erb pgtype_array_type=ACLItemArray pgtype_element_type=ACLItem go_array_types=[]string element_type_name=aclitem text_null=NULL binary_format=false typed_array.go.erb > aclitem_array.go
erb pgtype_array_type=HstoreArray pgtype_element_type=Hstore go_array_types=[]map[string]string element_type_name=hstore text_null=NULL binary_format=true typed_array.go.erb > hstore_array.go
erb pgtype_array_type=NumericArray pgtype_element_type=Numeric go_array_types=[]float32,[]float64 element_type_name=numeric text_null=NULL binary_format=true typed_array.go.erb > numeric_array.go
erb pgtype_array_type=UUIDArray pgtype_element_type=UUID go_array_types=[][16]byte,[][]byte,[]string element_type_name=uuid text_null=NULL binary_format=true typed_array.go.erb > uuid_array.go
goimports -w *_array.go

View File

@ -15,6 +15,7 @@ type UUIDArray struct {
}
func (dst *UUIDArray) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = UUIDArray{Status: Null}
return nil
@ -80,7 +81,7 @@ func (dst *UUIDArray) Set(src interface{}) error {
}
default:
if originalSrc, ok := underlyingPtrType(src); ok {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to UUIDArray", value)

View File

@ -15,6 +15,12 @@ type VarcharArray struct {
}
func (dst *VarcharArray) Set(src interface{}) error {
// untyped nil and typed nil interfaces are different
if src == nil {
*dst = VarcharArray{Status: Null}
return nil
}
switch value := src.(type) {
case []string:
@ -40,7 +46,7 @@ func (dst *VarcharArray) Set(src interface{}) error {
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)
}
return errors.Errorf("cannot convert %v to Varchar", value)
return errors.Errorf("cannot convert %v to VarcharArray", value)
}
return nil