gogmagog/models/models.go

43 lines
1.2 KiB
Go

package models
import (
"fmt"
)
// Store represents the backing store.
type Store interface {
ConnectionLive() error
SelectActions(userID int) ([]*Action, error)
SelectActionByID(id int, userID int) (*Action, error)
InsertAction(action *Action, userID int) (int, error)
UpdateAction(action *Action, userID int) error
SelectPlans(userID int) ([]*Plan, error)
SelectPlanByID(id int, userID int) (*Plan, error)
InsertPlan(plan *Plan, userID int) (int, error)
SelectActionsByPlanID(plan *Plan, userID int) ([]*Action, error)
SelectUserByUsername(username string) (*User, error)
InsertUser(user *User) (int, error)
SelectCurrentPlan(userID int) (*CurrentPlan, error)
InsertCurrentPlan(currentPlan *CurrentPlan, userID int) error
UpdateCurrentPlan(currentPlan *CurrentPlan, userID int) error
}
// Model represents a current model item.
type Model struct {
Store
}
// New creates an instance of the model using the passed in store.
func New(store Store) *Model {
return &Model{Store: store}
}
// Healthy returns an error if the connection is healthy.
// Wrapper over db.Ping()
func (m *Model) Healthy() error {
if m.Store == nil {
return fmt.Errorf("No store available")
}
return m.ConnectionLive()
}