googleapis / googleapis/google-cloud-go

Support `StructColumns()` helper that dervies column names from a go struct

Open
#13,800 0 comments 0 reactions 0 assignees View on GitHub
triage me
Dominant language
Go
Stars
4.5k
Forks
1.6k
Avg merge
1d 13h
Merged PRs (30d)
109

Description

## Is your feature request related to a problem? Please describe.
we already have `row.ToStruct()` that converts a row into a struct
but when we perform `Read()` it stills consume a `columns []string`, we have to define a string array (duplicate code + error prone)

## Describe the solution you'd like
once I defined a struct with `spanner` tag, I should be able to use it for any `Read`
this should be pretty easy to do, `spanner.StructColumns()` consumes a struct, using `reflect` package to get all the `spanner` tags for the columns names, if there's no tag, just use field name.

## Describe alternatives you've considered
I implemented this myself, or I manually create a string array (but this is a copy of the struct field name, in string)

## Additional context
in google's internal infra spanner, this `StructColumns` already exist, I think this utility is quite handy, we should make it public and discourage string[]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.