gogmagog/models/models.go
Deepak 3ea8603368
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
Adds user table and adds support for config flag to drop DB on restart
2021-01-11 20:15:36 -06:00

39 lines
898 B
Go

package models
import (
"fmt"
)
// Store represents the backing store.
type Store interface {
ConnectionLive() error
SelectActions() ([]*Action, error)
SelectActionByID(id int) (*Action, error)
InsertAction(action *Action) (int, error)
UpdateAction(action *Action) error
SelectPlans() ([]*Plan, error)
SelectPlanByID(id int) (*Plan, error)
InsertPlan(plan *Plan) (int, error)
SelectActionsByPlanID(plan *Plan) ([]*Action, error)
SelectUserByID(id int) (*User, 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()
}