well-goknown/db/db.go

24 lines
501 B
Go
Raw Normal View History

2024-08-10 23:55:16 +00:00
package db
import (
"git.minhas.io/asara/gologger"
"git.minhas.io/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())
}
err = db.Ping()
if err != nil {
l.Panic().Msg(err.Error())
}
l.Debug().Msg("connected to database")
return db, nil
}