forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
connection.go
35 lines (31 loc) · 938 Bytes
/
connection.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
package connections
import (
"database/sql"
"github.com/chenhg5/go-admin/modules/config"
"github.com/chenhg5/go-admin/modules/connections/mssql"
"github.com/chenhg5/go-admin/modules/connections/mysql"
"github.com/chenhg5/go-admin/modules/connections/postgresql"
"github.com/chenhg5/go-admin/modules/connections/sqlite"
)
type Connection interface {
Query(query string, args ...interface{}) ([]map[string]interface{}, *sql.Rows)
Exec(query string, args ...interface{}) sql.Result
InitDB(cfg map[string]config.Database)
}
func GetConnectionByDriver(driver string) Connection {
switch driver {
case "mysql":
return mysql.GetMysqlDB()
case "mssql":
return mssql.GetMssqlDB()
case "sqlite":
return sqlite.GetSqliteDB()
case "postgresql":
return postgresql.GetPostgresqlDB()
default:
panic("driver not found!")
}
}
func GetConnection() Connection {
return GetConnectionByDriver(config.Get().DATABASE[0].DRIVER)
}