Skip to content

Instantly share code, notes, and snippets.

@mkock
Created October 2, 2021 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkock/f17d772d13b63827391b6e39777fca87 to your computer and use it in GitHub Desktop.
Save mkock/f17d772d13b63827391b6e39777fca87 to your computer and use it in GitHub Desktop.
type UserRepository struct { }
func (u *UserRepository) Load(id uint32, h Hydrater) error {
row := ... // Run a SELECT by id and retrieve the result in a database.Row.
return h.Hydrate(row) // h must be a pointer.
}
type User struct {
ID uint32
Name string
// Other fields...
}
func (u *User) Hydrate(row database.Row) error {
return row.Scan(u)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment