-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patharchivemessages.go
57 lines (46 loc) · 1.28 KB
/
archivemessages.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
package database
import (
"context"
_ "embed"
"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/pgxpool"
)
type ArchiveMessage struct {
ChannelId uint64 `json:"channel_id,string"`
MessageId uint64 `json:"message_id,string"`
}
type ArchiveMessages struct {
*pgxpool.Pool
}
func newArchiveMessages(db *pgxpool.Pool) *ArchiveMessages {
return &ArchiveMessages{
db,
}
}
var (
//go:embed sql/archive_messages/schema.sql
archiveMessagesSchema string
//go:embed sql/archive_messages/insert.sql
archiveMessagesInsert string
//go:embed sql/archive_messages/get.sql
archiveMessagesGet string
)
func (a *ArchiveMessages) Schema() string {
return archiveMessagesSchema
}
func (a *ArchiveMessages) Set(ctx context.Context, guildId uint64, ticketId int, channelId, messageId uint64) error {
_, err := a.Exec(ctx, archiveMessagesInsert, guildId, ticketId, channelId, messageId)
return err
}
func (a *ArchiveMessages) Get(ctx context.Context, guildId uint64, ticketId int) (ArchiveMessage, bool, error) {
var data ArchiveMessage
err := a.QueryRow(ctx, archiveMessagesGet, guildId, ticketId).Scan(&data.ChannelId, &data.MessageId)
if err != nil {
if err == pgx.ErrNoRows {
return ArchiveMessage{}, false, nil
} else {
return ArchiveMessage{}, false, err
}
}
return data, true, nil
}