-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdiscordstoreskus.go
More file actions
45 lines (36 loc) · 892 Bytes
/
Copy pathdiscordstoreskus.go
File metadata and controls
45 lines (36 loc) · 892 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/TicketsBot/common/model"
"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/pgxpool"
)
type DiscordStoreSkus struct {
*pgxpool.Pool
}
var (
//go:embed sql/discord_store_skus/schema.sql
discordStoreSkusSchema string
//go:embed sql/discord_store_skus/get_sku.sql
discordStoreSkusGetSku string
)
func newDiscordStoreSkusTable(db *pgxpool.Pool) *DiscordStoreSkus {
return &DiscordStoreSkus{
db,
}
}
func (DiscordStoreSkus) Schema() string {
return discordStoreSkusSchema
}
func (e *DiscordStoreSkus) GetSku(ctx context.Context, discordId uint64) (*model.Sku, error) {
var sku model.Sku
if err := e.QueryRow(ctx, discordStoreSkusGetSku, discordId).Scan(&sku.Id, &sku.Label, &sku.SkuType); err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return nil, nil
}
return nil, err
}
return &sku, nil
}