well-goknown/db/db.go

23 lines
491 B
Go
Raw Normal View History

2024-08-10 23:55:16 +00:00
package db
import (
2024-08-15 00:38:38 +00:00
"git.devvul.com/asara/gologger"
"git.devvul.com/asara/well-goknown/config"
2024-08-10 23:55:16 +00:00
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
)
func NewDB() (*sqlx.DB, error) {
l := gologger.Get(config.GetConfig().LogLevel).With().Caller().Logger()
2024-08-10 23:55:16 +00:00
db, err := sqlx.Open("postgres", config.GetConfig().DbUrl)
if err != nil {
l.Panic().Msg(err.Error())
}
2024-08-17 19:18:55 +00:00
if err = db.Ping(); err != nil {
2024-08-10 23:55:16 +00:00
l.Panic().Msg(err.Error())
}
l.Debug().Msg("connected to database")
return db, nil
}