-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmultiserverskus.go
More file actions
45 lines (36 loc) · 930 Bytes
/
multiserverskus.go
File metadata and controls
45 lines (36 loc) · 930 Bytes
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
package database
import (
"context"
_ "embed"
"errors"
"github.com/google/uuid"
"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/pgxpool"
)
type MultiServerSkus struct {
*pgxpool.Pool
}
var (
//go:embed sql/multi_server_skus/schema.sql
multiServerSkusSchema string
//go:embed sql/multi_server_skus/get_permitted_server_count.sql
multiServerSkusGetPermittedServerCount string
)
func newMultiServerSkusTable(db *pgxpool.Pool) *MultiServerSkus {
return &MultiServerSkus{
db,
}
}
func (MultiServerSkus) Schema() string {
return multiServerSkusSchema
}
func (m *MultiServerSkus) GetPermittedServerCount(ctx context.Context, tx pgx.Tx, skuId uuid.UUID) (int, bool, error) {
var count int
if err := tx.QueryRow(ctx, multiServerSkusGetPermittedServerCount, skuId).Scan(&count); err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return 0, false, nil
}
return 0, false, err
}
return count, true, nil
}