-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopclosereasons.go
65 lines (52 loc) · 1.24 KB
/
topclosereasons.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
package analytics
import (
"context"
)
func (c *Client) GetTopCloseReasons(context context.Context, guildId uint64, panelId *int) ([]string, error) {
query := `
SELECT close_reason
FROM analytics.top_close_reasons
WHERE guild_id = ? AND panel_id = ?
ORDER BY ranking ASC
LIMIT 10`
rows, err := c.client.Query(context, query, guildId, panelId)
if err != nil {
return nil, err
}
defer rows.Close()
reasons := make([]string, 10)
i := 0
for rows.Next() {
var reason string
if err := rows.Scan(&reason); err != nil {
return nil, err
}
reasons[i] = reason
i++
}
return reasons[:i], nil
}
func (c *Client) GetTopCloseReasonsWithPrefix(context context.Context, guildId uint64, panelId *int, prefix string) ([]string, error) {
query := `
SELECT close_reason
FROM analytics.top_close_reasons
WHERE guild_id = ? AND panel_id = ? AND LOWER(close_reason) LIKE LOWER(?) || '%'
ORDER BY ranking ASC
LIMIT 10`
rows, err := c.client.Query(context, query, guildId, panelId, prefix)
if err != nil {
return nil, err
}
defer rows.Close()
reasons := make([]string, 10)
i := 0
for rows.Next() {
var reason string
if err := rows.Scan(&reason); err != nil {
return nil, err
}
reasons[i] = reason
i++
}
return reasons[:i], nil
}