googleapis / googleapis/google-cloud-go

datastore: load and write string representation of int enum

Open
#4,196 11 comments 1 reaction 1 assignee Assigned to @bhshkh View on GitHub
api: datastore type: feature request
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.**
I have issues loading enums from/saving enums to datastore.

**Describe the solution you'd like**
I would be great to use the `String` method if it exists on enums ? Or give a property like `datastore:",string"` to specify we want the string repr.
Maybe there is a solution I didn't found ?

**Describe alternatives you've considered**
I make it working by changing my enum to string but loose good (automatic) enum checks on my API.

**Additional context**
For example:
```
//go:generate enum Role -text -nosql -transform=kebab

type Role int

const (
Admin Role = iota
Standard
)

type User struct {
Name string
Role Role
}
```
This will save `1` for `admin` and `2` for `standard`. The issue is that I have Dataflow, and other stuffs, working with `admin` or `standard` string representation instead of the int value.

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.