-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update proto.ColumnDefinition (part of GetSchemaResponse) to include …
…column default and hydrate func. Closes #711
- Loading branch information
1 parent
81f438c
commit e3678bb
Showing
7 changed files
with
414 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package proto | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/golang/protobuf/ptypes" | ||
"google.golang.org/protobuf/reflect/protoreflect" | ||
) | ||
|
||
func (x *Column) ValueToInterface() (any, error) { | ||
// extract x value as interface from protobuf message | ||
var val any | ||
if bytes := x.GetJsonValue(); bytes != nil { | ||
if err := json.Unmarshal(bytes, &val); err != nil { | ||
return nil, err | ||
} | ||
} else if timestamp := x.GetTimestampValue(); timestamp != nil { | ||
// convert from protobuf timestamp to a RFC 3339 time string | ||
val = ptypes.TimestampString(timestamp) | ||
} else { | ||
// get the first field descriptor and value (we only expect x message to contain a single field | ||
x.ProtoReflect().Range(func(descriptor protoreflect.FieldDescriptor, v protoreflect.Value) bool { | ||
// is this value null? | ||
if descriptor.JSONName() == "nullValue" { | ||
val = nil | ||
} else { | ||
val = v.Interface() | ||
} | ||
return false | ||
}) | ||
} | ||
|
||
return val, nil | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters