You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

51 lines
971 B

package postgres
import (
"context"
"github.com/gissleh/stufflog/models"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
)
type Database struct {
db *sqlx.DB
}
func (d *Database) Goals() models.GoalRepository {
return &goalRepository{db: d.db}
}
func (d *Database) Groups() models.GroupRepository {
return &groupRepository{db: d.db}
}
func (d *Database) Items() models.ItemRepository {
return &itemRepository{db: d.db}
}
func (d *Database) Logs() models.LogRepository {
return &logRepository{db: d.db}
}
func (d *Database) Projects() models.ProjectRepository {
return &projectRepository{db: d.db}
}
func (d *Database) Tasks() models.TaskRepository {
return &taskRepository{db: d.db}
}
func Setup(ctx context.Context, connect string) (*Database, error) {
db, err := sqlx.ConnectContext(ctx, "postgres", connect)
if err != nil {
return nil, err
}
err = db.PingContext(ctx)
if err != nil {
return nil, err
}
return &Database{db: db}, nil
}