Remove Repository and use Database instead

This commit is contained in:
2021-12-11 20:18:09 +00:00
parent d5ebf5a5cf
commit e9adc763b2
14 changed files with 42 additions and 53 deletions

View File

@ -12,18 +12,26 @@ import (
//go:embed schema/*.sql
var migrations embed.FS
type Database struct {
*Queries
*sql.DB
}
// Connect to a database
func Connect(server string, user string, password string, database string) (*Queries, *sql.DB, error) {
func Connect(server string, user string, password string, database string) (*Database, error) {
connString := fmt.Sprintf("postgres://%s:%s@%s/%s", user, password, server, database)
conn, err := sql.Open("pgx", connString)
if err != nil {
return nil, nil, err
return nil, err
}
goose.SetBaseFS(migrations)
if err = goose.Up(conn, "schema"); err != nil {
return nil, nil, err
return nil, err
}
return New(conn), conn, nil
return &Database{
New(conn),
conn,
}, nil
}