Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spanner: Allow decoding Spanner values to custom types.
This change adds support for decoding result set values from Spanner into custom types that point back to supported types. This allows decoding a result set into for example a struct like this: type blobField []byte type dbProductInfo struct { ProductID int64 `spanner:"ProductID"` UpdateDate time.Time `spanner:"UpdateDate"` Data blobField `spanner:"Data"` } Decoding Spanner column values to one of the known types (string, []byte, int64, float64, time.Timestamp, civil.Date) and their known Null<type> versions is done using a type switch statement. Decoding to a custom type is done with reflection. The reason for not using reflection for all types, including the known base types, is the performance difference. Benchmark results executed locally showing the difference between the two are shown below based on decoding a single string value to a standard string or a custom string type. goos: linux goarch: amd64 pkg: cloud.google.com/go/spanner BenchmarkDecodeString-8 200000000 8.21 ns/op BenchmarkDecodeCustomString-8 10000000 135 ns/op Updates #1610. Fixes #853. Change-Id: Iad689b3704acadb83809375c762a7e0b564a7b2f Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/48090 Reviewed-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Tyler Bui-Palsulich <tbp@google.com> Reviewed-by: Hengfeng Li <hengfeng@google.com>
- Loading branch information
Showing
4 changed files
with
893 additions
and
100 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
Oops, something went wrong.