2
0

Fixes #11 -- support initializing Array types from a slice of the value

This commit is contained in:
Alex Gaynor
2019-11-08 14:59:19 -05:00
parent f711de3591
commit 0079108e29
22 changed files with 327 additions and 80 deletions
+14
View File
@@ -23,6 +23,7 @@ func (dst *<%= pgtype_array_type %>) Set(src interface{}) error {
switch value := src.(type) {
<% go_array_types.split(",").each do |t| %>
<% if t != pgtype_element_type %>
case <%= t %>:
if value == nil {
*dst = <%= pgtype_array_type %>{Status: Null}
@@ -42,6 +43,19 @@ func (dst *<%= pgtype_array_type %>) Set(src interface{}) error {
}
}
<% end %>
<% end %>
case []<%= pgtype_element_type %>:
if value == nil {
*dst = <%= pgtype_array_type %>{Status: Null}
} else if len(value) == 0 {
*dst = <%= pgtype_array_type %>{Status: Present}
} else {
*dst = <%= pgtype_array_type %>{
Elements: value,
Dimensions: []ArrayDimension{{Length: int32(len(value)), LowerBound: 1}},
Status : Present,
}
}
default:
if originalSrc, ok := underlyingSliceType(src); ok {
return dst.Set(originalSrc)