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) {
|
2024-09-17 01:01:42 +00:00
|
|
|
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
|
|
|
|
}
|