well-goknown/db/db.go
2024-08-17 15:26:53 -04:00

23 lines
503 B
Go

package db
import (
"git.devvul.com/asara/gologger"
"git.devvul.com/asara/well-goknown/config"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
)
func NewDB() (*sqlx.DB, error) {
l := gologger.Get(config.GetConfig().LogLevel).With().Str("context", "db").Logger()
db, err := sqlx.Open("postgres", config.GetConfig().DbUrl)
if err != nil {
l.Panic().Msg(err.Error())
}
if err = db.Ping(); err != nil {
l.Panic().Msg(err.Error())
}
l.Debug().Msg("connected to database")
return db, nil
}