-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.go
69 lines (61 loc) · 1.2 KB
/
database.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
package main
import (
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
)
var Database *sqlx.DB
var (
lastPlayedStmt *sqlx.Stmt
queueStmt *sqlx.Stmt
mainStmt *sqlx.Stmt
)
func openDatabase(dsn string) error {
var err error
Database, err = sqlx.Open("mysql", dsn)
if err != nil {
return err
}
lastPlayedStmt, err = Database.Preparex("SELECT esong.meta AS meta, UNIX_TIMESTAMP(eplay.dt) AS timestamp FROM `eplay` LEFT JOIN `esong` ON eplay.isong = esong.id ORDER BY eplay.dt DESC LIMIT 5;")
if err != nil {
return err
}
queueStmt, err = Database.Preparex("SELECT meta AS meta, UNIX_TIMESTAMP(time) AS timestamp, type FROM `queue` ORDER BY `time` ASC LIMIT 5;")
if err != nil {
return err
}
mainStmt, err = Database.Preparex(`
SELECT
np,
listeners,
bitrate,
djid,
isafkstream,
isstreamdesk,
start_time,
end_time,
lastset,
trackid,
thread,
requesting,
djs.djname,
djtext,
djimage,
visible,
css,
djcolor,
theme_id,
djs.priority AS priority,
role,
tracks.tags AS tags
FROM
streamstatus
JOIN
djs ON djs.id = djid
LEFT JOIN
tracks ON tracks.id = streamstatus.trackid
LIMIT 1;`)
if err != nil {
return err
}
return nil
}