Created
October 1, 2018 21:19
-
-
Save berfarah/cddfe2ef07bac1c1ac265a59ebd11f19 to your computer and use it in GitHub Desktop.
Iterative Optimization on Hot Paths: Storing JSON in the database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type User struct { | |
ID int64 `sql:",primary"` | |
Name string | |
Configuration Configuration `sql:",json"` | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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