-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstore.go
42 lines (33 loc) · 858 Bytes
/
store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package postgres
import (
"context"
"database/sql"
"github.com/jmoiron/sqlx"
"github.com/code-payments/code-server/pkg/code/data/airdrop"
)
type store struct {
db *sqlx.DB
}
// New returns a new postgres airdrop.Store
func New(db *sql.DB) airdrop.Store {
return &store{
db: sqlx.NewDb(db, "pgx"),
}
}
// MarkIneligible implements airdrop.Store.MarkIneligible
func (s *store) MarkIneligible(ctx context.Context, owner string) error {
model, err := toIneligibleModel(owner)
if err != nil {
return err
}
return model.dbPut(ctx, s.db)
}
// IsEligible implements airdrop.Store.IsEligible
func (s *store) IsEligible(ctx context.Context, owner string) (bool, error) {
model, err := dbGet(ctx, s.db, owner)
if err == errNotFound {
// Backwards compatibility with a default true value
return true, nil
}
return model.IsEligible, nil
}