Update NewClient to actually work

pull/2/head
Vinícius Garcia 2020-09-14 15:45:35 -03:00
parent 06a7e37d0e
commit a3af26e3bd
1 changed files with 14 additions and 3 deletions

View File

@ -15,10 +15,21 @@ type Client struct {
}
// NewClient ...
func NewClient(tableName string) Client {
return Client{
tableName: tableName,
func NewClient(dbDriver string, connectionString string, maxOpenConns int) (Client, error) {
db, err := gorm.Open(dbDriver, connectionString)
if err != nil {
return Client{}, err
}
if err = db.DB().Ping(); err != nil {
return Client{}, err
}
db.DB().SetMaxOpenConns(maxOpenConns)
return Client{
db: db,
}, nil
}
// Find one instance from the database, the input struct