-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmysql.go
More file actions
48 lines (38 loc) · 933 Bytes
/
mysql.go
File metadata and controls
48 lines (38 loc) · 933 Bytes
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
package cycapi
import (
"database/sql"
"fmt"
"github.com/getsentry/sentry-go"
_ "github.com/go-sql-driver/mysql"
)
type MysqlConn struct {
Conn *sql.DB
}
func CreateMysqlConnection(host string, username string, password string, dbname string) (DB *MysqlConn, err error) {
dbConn, err := sql.Open(
"mysql",
fmt.Sprintf("%s:%s@tcp(%s)/%s", username, password, host, dbname ),
)
if err != nil {
return DB, err
}
Database := MysqlConn{
Conn: dbConn,
}
return &Database, err
}
func (db *MysqlConn) Query(query string, args interface{}) (rows *sql.Rows, err error) {
rows, err = db.Conn.Query(query, args)
if err != nil {
sentry.CaptureException(err)
}
return
}
func (db *MysqlConn) QueryRow(query string, args interface{}) (row *sql.Row) {
row = db.Conn.QueryRow(query, args)
return
}
// CloseConnection Closes a DB Connection
func (db *MysqlConn) CloseConnection() error {
return db.Conn.Close()
}