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/go-redis/redis/v8"
|
||||||
"github.com/gorilla/handlers"
|
"github.com/gorilla/handlers"
|
||||||
"github.com/gorilla/mux"
|
"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/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/common"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@@ -700,13 +700,27 @@ func main() {
|
|||||||
Lock: new(sync.RWMutex),
|
Lock: new(sync.RWMutex),
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Client, err = ent.Open(conf.Db.Driver, conf.Db.ConnectTo)
|
if conf.Db.Driver == "pgx" {
|
||||||
if err != nil {
|
pdb, err := sql.Open("pgx", conf.Db.ConnectTo)
|
||||||
log.Panicf("Failed to open database %s: %v", conf.Db.ConnectTo, err)
|
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(
|
if err := db.Client.Schema.Create(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
|
Reference in New Issue
Block a user