Skip to content

feat(spanner): support "readOnly" column tag parsing for Go struct operations#12895

Merged
rahul2393 merged 1 commit intomainfrom
fix-8933
Sep 17, 2025
Merged

feat(spanner): support "readOnly" column tag parsing for Go struct operations#12895
rahul2393 merged 1 commit intomainfrom
fix-8933

Conversation

@rahul2393
Copy link
Copy Markdown
Contributor

Fixes: #8933

@rahul2393 rahul2393 requested review from a team September 17, 2025 06:52
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Sep 17, 2025
@rahul2393 rahul2393 requested a review from olavloite September 17, 2025 06:58
spanner/value.go Outdated
name = parts[0]
tag := spannerTag{}
for _, part := range parts[1:] {
if part == "generated" {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above; Should we consider using readOnly instead for this? Or is there prior art / precedence from other databases or frameworks that indicate that generated is a more common term?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we talk about GORM they support something like

  Name string `gorm:"->"`        // readonly (disable write permission unless it configured)

Copy link
Copy Markdown
Contributor Author

@rahul2393 rahul2393 Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated PR to use readOnly as well as how GORM parses this ->

parts := strings.Split(s, ",")
name = parts[0]
tag := spannerTag{}
for _, part := range parts[1:] {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we skip the first result here? Is it because it should always be parsed as the column name?

Can we add some documentation (code comments) that explains what can go into this tag, and how it should be used (including this new tag)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we skip the first result here? Is it because it should always be parsed as the column name?

Yes, and if we don't skip it, it will be a breaking change for existing users.

Copy link
Copy Markdown
Contributor Author

@rahul2393 rahul2393 Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added doc.go, now instead of comma optional tags will be separate by a semicolan (;) and -> is supported similar to GORM https://gorm.io/docs/models.html#Fields-Tags

@rahul2393 rahul2393 requested a review from olavloite September 17, 2025 08:53
@rahul2393 rahul2393 changed the title feat(spanner): support "generated" column tag parsing for Go struct operations feat(spanner): support "readOnly" column tag parsing for Go struct operations Sep 17, 2025
@rahul2393 rahul2393 merged commit 003abca into main Sep 17, 2025
10 checks passed
@rahul2393 rahul2393 deleted the fix-8933 branch September 17, 2025 18:06
rahul2393 pushed a commit that referenced this pull request Sep 29, 2025
🤖 I have created a release *beep* *boop*
---


##
[1.86.0](spanner/v1.85.1...spanner/v1.86.0)
(2025-09-26)


### Features

* **spanner:** Support "readOnly" column tag parsing for Go struct
operations
([#12895](#12895))
([003abca](003abca))


### Bug Fixes

* **spanner:** Use fresh context for rollback
([#12897](#12897))
([99c7eeb](99c7eeb))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spanner: support generated column with spanner#Row.ToStruct, spanner.(Insert|Update|InsertOrUpdate)Struct

2 participants