Skip to content

Instantly share code, notes, and snippets.

@berfarah
Created October 1, 2018 21:19
Show Gist options
  • Save berfarah/cddfe2ef07bac1c1ac265a59ebd11f19 to your computer and use it in GitHub Desktop.
Save berfarah/cddfe2ef07bac1c1ac265a59ebd11f19 to your computer and use it in GitHub Desktop.
Iterative Optimization on Hot Paths: Storing JSON in the database
type User struct {
ID int64 `sql:",primary"`
Name string
Configuration Configuration `sql:",json"`
}
func (s *UserRepository) Update(ctx context.Context, u *User) error {
return s.DB.Update(ctx, &u)
}
func (s *UserRepository) ById(ctx context.Context, id int64) (*User, error) {
var user *User
if err := s.DB.QueryRow(ctx, &user); err != nil {
return nil, err
}
return user, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment