Ajouter data.NewDataClientFromViper()

This commit is contained in:
Victor Lacasse-Beaudoin 2023-06-02 02:44:11 -04:00
parent 4673612e06
commit 80a0260021

View file

@ -7,6 +7,7 @@ import (
"git.agecem.com/agecem/bottin/v4/models"
_ "github.com/jackc/pgx/stdlib"
"github.com/jmoiron/sqlx"
"github.com/spf13/viper"
)
// DataClient is a postgres client based on sqlx
@ -24,6 +25,19 @@ type PostgresConnection struct {
SSL bool
}
func NewDataClientFromViper() (*DataClient, error) {
client, err := NewDataClient(
PostgresConnection{
User: viper.GetString("db.user"),
Password: viper.GetString("db.password"),
Host: viper.GetString("db.host"),
Database: viper.GetString("db.database"),
Port: viper.GetInt("db.port"),
})
return client, err
}
func NewDataClient(connection PostgresConnection) (*DataClient, error) {
client := &DataClient{PostgresConnection: connection}