-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmessages_database.go
56 lines (46 loc) · 1.09 KB
/
messages_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
package evtx
import (
"database/sql"
)
type DBResolver struct {
db *sql.DB
query *sql.Stmt
}
// TODO: What is happening with the channel here?
func (self *DBResolver) GetMessage(
provider, channel string, event_id, number_of_expansions int) string {
rows, err := self.query.Query(provider, event_id)
if err != nil {
return ""
}
defer rows.Close()
for rows.Next() {
var message string
err = rows.Scan(&message)
if err == nil {
return message
}
}
return ""
}
func (self *DBResolver) GetParameter(provider, channel string, parameter_id int) string {
return ""
}
func (self *DBResolver) Close() {
self.db.Close()
}
func NewDBResolver(message_file string) (*DBResolver, error) {
database, err := sql.Open("sqlite3", message_file)
if err != nil {
return nil, err
}
query, err := database.Prepare(`
SELECT message
FROM messages left join providers ON messages.provider_id = providers.id
WHERE providers.name = ? and messages.event_id = ?
`)
if err != nil {
return nil, err
}
return &DBResolver{db: database, query: query}, nil
}