mirror of
https://github.com/eduardolat/pgbackweb.git
synced 2026-05-18 02:33:25 -05:00
Add .gitignore for generated database files and implement database connection functionality
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
# Ignore the generated files to avoid git conflicts
|
||||
dbgen/
|
||||
@@ -0,0 +1,36 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/eduardolat/pgbackweb/internal/config"
|
||||
"github.com/eduardolat/pgbackweb/internal/logger"
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
func Connect(env *config.Env) *sql.DB {
|
||||
db, err := sql.Open("postgres", *env.PBW_POSTGRES_CONN_STRING)
|
||||
if err != nil {
|
||||
logger.FatalError(
|
||||
"Could not connect to DB",
|
||||
logger.KV{
|
||||
"error": err,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
err = db.Ping()
|
||||
if err != nil {
|
||||
logger.FatalError(
|
||||
"Could not ping DB",
|
||||
logger.KV{
|
||||
"error": err,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
db.SetMaxOpenConns(10)
|
||||
logger.Info("Connected to DB")
|
||||
|
||||
return db
|
||||
}
|
||||
Reference in New Issue
Block a user