Added db.go
This commit is contained in:
parent
9496947f01
commit
b7595b4c7b
1 changed files with 43 additions and 0 deletions
43
db.go
Normal file
43
db.go
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
// External
|
||||||
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
|
|
||||||
|
// Standard
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
db *pgxpool.Pool
|
||||||
|
)
|
||||||
|
|
||||||
|
func initDb(host string, port int, name, username, password string) (err error) {
|
||||||
|
// The main database connection is configured.
|
||||||
|
connString := fmt.Sprintf(
|
||||||
|
"host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
name,
|
||||||
|
)
|
||||||
|
db, err = pgxpool.New(context.Background(), connString)
|
||||||
|
|
||||||
|
// The schema upgrader keeps track of the SQL schema version and
|
||||||
|
// runs SQL scripts to upgrade it if necessary.
|
||||||
|
/*
|
||||||
|
upgrader := dbschema.NewUpgrader("_jsonstore")
|
||||||
|
upgrader.SetLogCallback(sqlLogCallback)
|
||||||
|
upgrader.SetSqlCallback(sqlSourceCallback)
|
||||||
|
|
||||||
|
_, err = upgrader.AddDatabaseInstance(db, config.Database.Db)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = upgrader.Run()
|
||||||
|
*/
|
||||||
|
return
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue