26 lines
495 B
Go
26 lines
495 B
Go
package profile
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
type Repository struct {
|
|
db *sql.DB
|
|
}
|
|
|
|
func NewRepository(db *sql.DB) Repository {
|
|
return Repository{db: db}
|
|
}
|
|
|
|
func (r Repository) Ensure(ctx context.Context, id string, email string) error {
|
|
_, err := r.db.ExecContext(ctx, `
|
|
insert into public.profiles (id, email)
|
|
values ($1, $2)
|
|
on conflict (id) do update
|
|
set email = excluded.email
|
|
where public.profiles.email is distinct from excluded.email
|
|
`, id, email)
|
|
return err
|
|
}
|