8000 use custom type marshalling via database/sql interface by cryptix · Pull Request #120 · ssbc/go-ssb-room · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

use custom type marshalling via database/sql interface #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2021

Conversation

cryptix
Copy link
Member
@cryptix cryptix commented Apr 7, 2021
  • remove cruft from sqlite package
  • update sqlboiler.toml
  • fix default value in migration
  • add default tests

* remove cruft from sqlite package
* update sqlboiler.toml
* fix default value in migration
* add default tests
@cryptix cryptix requested a review from cblgh April 7, 2021 06:55
@cryptix cryptix added the Go golang related stuff label Apr 7, 2021

// Scan implements https://pkg.go.dev/database/sql#Scanner to read integers into a privacy mode
func (pm *PrivacyMode) Scan(src interface{}) error {
dbValue, ok := src.(int64)
Copy link
Member Author
@cryptix cryptix Apr 7, 2021

Choose a reason for hiding this comment

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

This was src.(PrivacyMode) before, but the compiler needs to know what the database stores it as internally first.

return err
}

*pm = privacyMode
Copy link
Member Author
@cryptix cryptix Apr 7, 2021

Choose a reason for hiding this comment

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

You had pm = &privacyMode which pleases compiler semantics (left type == right type) but doesn't effect the change you want.

That way just overwrites the pointer in the scope of Scan() with a pointer to the value that was just created inside that function. As soon as the function returns, they will be gone.

The receiver *pm already points to a valid PrivacyMode, it needs to be dereferenced so that we can update the value inside, updating the number from it's zero value to the one we got from the DB.

HTH

@cblgh
Copy link
Contributor
cblgh commented Apr 7, 2021

thanks for finishing this up @cryptix, i think i understand a bit more what i was missing in my attempt.

@cryptix cryptix merged commit 9286e9f into master Apr 7, 2021
@cryptix cryptix deleted the pm-orm-stuff branch April 7, 2021 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Go golang related stuff
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0