-
Notifications
You must be signed in to change notification settings - Fork 402
/
db.go
47 lines (39 loc) · 1.35 KB
/
db.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
43
44
45
46
47
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
// Package attribution implements value attribution from docs/design/value-attribution.md
package attribution
import (
"context"
"time"
"github.com/zeebo/errs"
"storj.io/common/uuid"
)
// ErrBucketNotAttributed is returned if a requested bucket not attributed(entry not found).
var ErrBucketNotAttributed = errs.Class("bucket not attributed")
// Info describing value attribution from partner to bucket.
type Info struct {
ProjectID uuid.UUID
BucketName []byte
PartnerID uuid.UUID
CreatedAt time.Time
}
// CSVRow represents data from QueryAttribution without exposing dbx.
type CSVRow struct {
PartnerID []byte
ProjectID []byte
BucketName []byte
RemoteBytesPerHour float64
InlineBytesPerHour float64
EgressData int64
}
// DB implements the database for value attribution table.
//
// architecture: Database
type DB interface {
// Get retrieves attribution info using project id and bucket name.
Get(ctx context.Context, projectID uuid.UUID, bucketName []byte) (*Info, error)
// Insert creates and stores new Info
Insert(ctx context.Context, info *Info) (*Info, error)
// QueryAttribution queries partner bucket attribution data
QueryAttribution(ctx context.Context, partnerID uuid.UUID, start time.Time, end time.Time) ([]*CSVRow, error)
}