package main import ( "context" "atlas9.dev/c/core" "atlas9.dev/c/core/dbi" ) type Profile struct { UserID core.ID Name string Bio string Location string Website string PictureURL string } type ProfileStore struct { db dbi.DBI } func NewProfileStore(db dbi.DBI) *ProfileStore { return &ProfileStore{db: db} } func (s *ProfileStore) Get(ctx context.Context, userID core.ID) (*Profile, error) { var p Profile err := dbi.Get(ctx, s.db, &p, ` SELECT user_id, name, bio, location, website, picture_url FROM profiles WHERE user_id = $1 `, userID) return &p, err } func (s *ProfileStore) Save(ctx context.Context, p *Profile) error { _, err := s.db.Exec(ctx, ` INSERT INTO profiles (user_id, name, bio, location, website, picture_url) VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT (user_id) DO UPDATE SET name = excluded.name, bio = excluded.bio, location = excluded.location, website = excluded.website, picture_url = excluded.picture_url `, p.UserID, p.Name, p.Bio, p.Location, p.Website, p.PictureURL) return err }