separate profile model from account model
This commit is contained in:
parent
f729160209
commit
c3271d7dcf
15 changed files with 152 additions and 83 deletions
34
database/profileStore.go
Normal file
34
database/profileStore.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/dhax/go-base/models"
|
||||
"github.com/go-pg/pg"
|
||||
)
|
||||
|
||||
// ProfileStore implements database operations for profile management.
|
||||
type ProfileStore struct {
|
||||
db *pg.DB
|
||||
}
|
||||
|
||||
// NewProfileStore returns a ProfileStore implementation.
|
||||
func NewProfileStore(db *pg.DB) *ProfileStore {
|
||||
return &ProfileStore{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
// Get gets an profile by account ID.
|
||||
func (s *ProfileStore) Get(accountID int) (*models.Profile, error) {
|
||||
p := models.Profile{AccountID: accountID}
|
||||
_, err := s.db.Model(&p).
|
||||
Where("account_id = ?", accountID).
|
||||
SelectOrInsert()
|
||||
|
||||
return &p, err
|
||||
}
|
||||
|
||||
// Update updates profile.
|
||||
func (s *ProfileStore) Update(p *models.Profile) error {
|
||||
err := s.db.Update(p)
|
||||
return err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue