-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcategoryupdatequeue.go
66 lines (53 loc) · 1.52 KB
/
categoryupdatequeue.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
package database
import (
"context"
_ "embed"
"github.com/TicketsBot/common/model"
"github.com/jackc/pgx/v4/pgxpool"
"time"
)
type CategoryUpdateQueue struct {
*pgxpool.Pool
}
type CategoryUpdateQueueItem struct {
GuildId uint64
TicketId int
NewStatus model.TicketStatus
ChannelId *uint64
PanelId *int
}
var (
//go:embed sql/category_update_queue/schema.sql
categoryUpdateQueueSchema string
//go:embed sql/category_update_queue/add.sql
categoryUpdateQueueAdd string
//go:embed sql/category_update_queue/get_ready_for_update.sql
categoryUpdateQueueGetReadyForUpdate string
)
func newCategoryUpdateQueueTable(db *pgxpool.Pool) *CategoryUpdateQueue {
return &CategoryUpdateQueue{
db,
}
}
func (CategoryUpdateQueue) Schema() string {
return categoryUpdateQueueSchema
}
func (q *CategoryUpdateQueue) Add(ctx context.Context, guildId uint64, ticketId int, newStatus model.TicketStatus) error {
_, err := q.Exec(ctx, categoryUpdateQueueAdd, guildId, ticketId, newStatus)
return err
}
func (q *CategoryUpdateQueue) GetReadyForUpdate(ctx context.Context, delayInterval time.Duration) ([]CategoryUpdateQueueItem, error) {
rows, err := q.Query(ctx, categoryUpdateQueueGetReadyForUpdate, delayInterval)
if err != nil {
return nil, err
}
var items []CategoryUpdateQueueItem
for rows.Next() {
var item CategoryUpdateQueueItem
if err := rows.Scan(&item.GuildId, &item.TicketId, &item.NewStatus, &item.ChannelId, &item.PanelId); err != nil {
return nil, err
}
items = append(items, item)
}
return items, nil
}