feat: add profile sync
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user