-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstore.go
40 lines (32 loc) · 863 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
package postgres
import (
"context"
"database/sql"
"github.com/jmoiron/sqlx"
"github.com/code-payments/code-server/pkg/code/data/badgecount"
)
type store struct {
db *sqlx.DB
}
// New returns a new postgres badgecount.Store
func New(db *sql.DB) badgecount.Store {
return &store{
db: sqlx.NewDb(db, "pgx"),
}
}
// Add implements badgecount.Store.Add
func (s *store) Add(ctx context.Context, owner string, amount uint32) error {
return dbAdd(ctx, s.db, owner, amount)
}
// Reset implements badgecount.Store.Reset
func (s *store) Reset(ctx context.Context, owner string) error {
return dbReset(ctx, s.db, owner)
}
// Get implements badgecount.Store.Get
func (s *store) Get(ctx context.Context, owner string) (*badgecount.Record, error) {
model, err := dbGet(ctx, s.db, owner)
if err != nil {
return nil, err
}
return fromModel(model), nil
}