-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection-options.go
49 lines (41 loc) · 1009 Bytes
/
connection-options.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
package main
import (
"fmt"
"time"
"github.com/pcpratheesh/dbmux"
"github.com/pcpratheesh/dbmux/driver"
"github.com/pcpratheesh/dbmux/driver/options"
"github.com/pcpratheesh/dbmux/entity"
)
func main() {
mysql_1 := entity.Options{
Name: "mysql_1",
Driver: driver.MYSQL,
Host: "localhost",
User: "root",
Password: "root",
Database: "db",
Port: 3306,
ConnectionOptions: []entity.ConnectionOptions{
options.SetConnMaxLifetime(10 * time.Second),
options.SetConnMaxIdleTime(30 * time.Second),
options.SetMaxOpenConns(5),
options.SetMaxIdleConns(2),
},
}
var dbConnections = []entity.Options{
mysql_1,
}
// this will initiate the connection
dbmuxConn := dbmux.New(dbConnections...)
// get the psql connection pool
{
mysqlConnection, err := dbmuxConn.GetConnection("mysql_1")
if err != nil {
panic(err)
}
mysqlDB := dbmux.GetConnectionPool[entity.SqlDB](mysqlConnection)
_ = mysqlDB
}
fmt.Println("dbmux connection initiated")
}