Also return sql.DB to be able to use goose

This commit is contained in:
2021-12-02 20:36:22 +00:00
parent a3df95a700
commit 4011f3cace
3 changed files with 14 additions and 15 deletions

View File

@ -15,29 +15,24 @@ import (
var migrations embed.FS
// Connect to a database
func Connect(server string, user string, password string, database string) (*Queries, error) {
func Connect(server string, user string, password string, database string) (*Queries, *sql.DB, error) {
connString := fmt.Sprintf("postgres://%s:%s@%s/%s", user, password, server, database)
conn, err := sql.Open("pgx", connString)
if err != nil {
return nil, err
return nil, nil, err
}
goose.SetBaseFS(migrations)
if err = goose.Up(conn, "schema"); err != nil {
return nil, err
}
err = conn.Close()
if err != nil {
return nil, err
return nil, nil, err
}
connPG, err := pgx.Connect(context.Background(), connString)
if err != nil {
return nil, err
return nil, nil, err
}
return New(connPG), nil
return New(connPG), conn, nil
}
func (tx Transaction) GetAmount() float64 {