-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlegacypremiumentitlementguilds.go
82 lines (64 loc) · 2.44 KB
/
legacypremiumentitlementguilds.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package database
import (
"context"
_ "embed"
"github.com/google/uuid"
"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/pgxpool"
)
type LegacyPremiumEntitlementGuildRecord struct {
UserId uint64 `json:"user_id"`
GuildId uint64 `json:"guild_id"`
EntitlementId uuid.UUID `json:"entitlement_id"`
}
type LegacyPremiumEntitlementGuilds struct {
*pgxpool.Pool
}
var (
//go:embed sql/legacy_premium_entitlement_guilds/schema.sql
legacyPremiumEntitlementGuildsSchema string
//go:embed sql/legacy_premium_entitlement_guilds/list_for_user.sql
legacyPremiumEntitlementGuildsListForUser string
//go:embed sql/legacy_premium_entitlement_guilds/insert.sql
legacyPremiumEntitlementGuildsInsert string
//go:embed sql/legacy_premium_entitlement_guilds/delete.sql
legacyPremiumEntitlementGuildsDelete string
//go:embed sql/legacy_premium_entitlement_guilds/delete_by_entitlement.sql
legacyPremiumEntitlementGuildsDeleteByEntitlement string
)
func newLegacyPremiumEntitlementGuildsTable(db *pgxpool.Pool) *LegacyPremiumEntitlementGuilds {
return &LegacyPremiumEntitlementGuilds{
db,
}
}
func (LegacyPremiumEntitlementGuilds) Schema() string {
return legacyPremiumEntitlementGuildsSchema
}
func (g *LegacyPremiumEntitlementGuilds) ListForUser(ctx context.Context, tx pgx.Tx, userId uint64) ([]LegacyPremiumEntitlementGuildRecord, error) {
rows, err := tx.Query(ctx, legacyPremiumEntitlementGuildsListForUser, userId)
if err != nil {
return nil, err
}
defer rows.Close()
records := make([]LegacyPremiumEntitlementGuildRecord, 0)
for rows.Next() {
var record LegacyPremiumEntitlementGuildRecord
if err := rows.Scan(&record.UserId, &record.GuildId, &record.EntitlementId); err != nil {
return nil, err
}
records = append(records, record)
}
return records, nil
}
func (g *LegacyPremiumEntitlementGuilds) Insert(ctx context.Context, tx pgx.Tx, userId, guildId uint64, entitlementId uuid.UUID) error {
_, err := tx.Exec(ctx, legacyPremiumEntitlementGuildsInsert, userId, guildId, entitlementId)
return err
}
func (g *LegacyPremiumEntitlementGuilds) Delete(ctx context.Context, tx pgx.Tx, userId, guildId uint64) error {
_, err := tx.Exec(ctx, legacyPremiumEntitlementGuildsDelete, userId, guildId)
return err
}
func (g *LegacyPremiumEntitlementGuilds) DeleteByEntitlement(ctx context.Context, tx pgx.Tx, entitlementId uuid.UUID) error {
_, err := tx.Exec(ctx, legacyPremiumEntitlementGuildsDeleteByEntitlement, entitlementId)
return err
}