added pgx handling
This commit is contained in:
28
main.go
28
main.go
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/go-redis/redis/v8"
|
||||
"github.com/gorilla/handlers"
|
||||
"github.com/gorilla/mux"
|
||||
_ "github.com/jackc/pgx/v4"
|
||||
_ "github.com/jackc/pgx/v4/stdlib"
|
||||
"github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/common"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -700,13 +700,27 @@ func main() {
|
||||
Lock: new(sync.RWMutex),
|
||||
}
|
||||
|
||||
db.Client, err = ent.Open(conf.Db.Driver, conf.Db.ConnectTo)
|
||||
if err != nil {
|
||||
log.Panicf("Failed to open database %s: %v", conf.Db.ConnectTo, err)
|
||||
if conf.Db.Driver == "pgx" {
|
||||
pdb, err := sql.Open("pgx", conf.Db.ConnectTo)
|
||||
if err != nil {
|
||||
log.Panicf("Failed to open database %s: %v", conf.Db.ConnectTo, err)
|
||||
}
|
||||
|
||||
defer func(db *sql.Driver) {
|
||||
_ = db.Close()
|
||||
}(pdb)
|
||||
|
||||
drv := sql.OpenDB("postgres", pdb.DB())
|
||||
db.Client = ent.NewClient(ent.Driver(drv))
|
||||
} else {
|
||||
db.Client, err = ent.Open(conf.Db.Driver, conf.Db.ConnectTo)
|
||||
if err != nil {
|
||||
log.Panicf("Failed to open database %s: %v", conf.Db.ConnectTo, err)
|
||||
}
|
||||
defer func(Client *ent.Client) {
|
||||
_ = Client.Close()
|
||||
}(db.Client)
|
||||
}
|
||||
defer func(Client *ent.Client) {
|
||||
_ = Client.Close()
|
||||
}(db.Client)
|
||||
|
||||
if err := db.Client.Schema.Create(
|
||||
context.Background(),
|
||||
|
Reference in New Issue
Block a user