RestApiv2/internal/bd/bd.go

35 lines
418 B
Go
Raw Normal View History

2022-12-12 20:34:00 +03:00
package bd
import (
"database/sql"
_ "github.com/lib/pq"
)
type Bd struct {
config *ConfigBD
db *sql.DB
}
func New(config *ConfigBD) *Bd {
return &Bd{
config: config,
}
}
func (b *Bd) Open() error {
db, err := sql.Open("postgres", b.config.BaseUrlBd)
if err != nil {
return err
}
if err := db.Ping(); err != nil {
return err
}
b.db = db
return nil
}
func (b *Bd) Close() {
b.db.Close()
}