Documentation ¶
Index ¶
- Constants
- type Change
- type Manager
- func (m *Manager) Applied() []*Change
- func (m *Manager) Clear()
- func (m *Manager) Commit() error
- func (m *Manager) Get(model interfaces.Model, id interface{}) error
- func (m *Manager) PrintStatus()
- func (m *Manager) Query(mList interface{}, model interfaces.Model, query ...string) error
- func (m *Manager) QueryOne(model interfaces.Model, query string) error
- func (m *Manager) RawQuery(mList interface{}, model interfaces.Model, query ...string) error
- func (m *Manager) Rollback() error
- func (m *Manager) Stage(model interfaces.Model, operation string) error
- func (m *Manager) Status() []*Change
- func (m *Manager) ToggleLogs()
Constants ¶
const ( INSERT = "insert" UPDATE = "update" DELETE = "delete" )
Operation codes
const ( PENDING = "pending" SUCCESS = "success" FAILURE = "failure" REVERTED = "reverted" )
Status codes
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change struct {
// contains filtered or unexported fields
}
Change defines the current state of a model that has been staged for changed
func NewChange ¶
func NewChange(m interfaces.Model, operation string) (*Change, error)
NewChange creates a new Change struct which is reponsible for tracking changes applied to the application state
func (*Change) Apply ¶
func (ch *Change) Apply(db interfaces.Database, cache interfaces.Cache) error
Apply executes a pending change
func (*Change) Revert ¶
func (ch *Change) Revert(db interfaces.Database, cache interfaces.Cache) error
Revert executes the reverse action of a change, currently only supports insert
type Manager ¶
type Manager struct { DB interfaces.Database Cache interfaces.Cache // contains filtered or unexported fields }
Manager defines an application state controller
func New ¶
func New(db interfaces.Database, cache interfaces.Cache) (*Manager, error)
New creates a new Application State Manager from storage. It supports using a Database and a Cache or one of both.
func (*Manager) Get ¶
func (m *Manager) Get(model interfaces.Model, id interface{}) error
Get obtains a model from the database using its ID, will attempt to fetch it first from Cache and then from Database
func (*Manager) PrintStatus ¶
func (m *Manager) PrintStatus()
PrintStatus display the current status of staged changes
func (*Manager) Query ¶
func (m *Manager) Query(mList interface{}, model interfaces.Model, query ...string) error
Query receives a model and a query. Will return all models that satisfies the query.
func (*Manager) QueryOne ¶
func (m *Manager) QueryOne(model interfaces.Model, query string) error
QueryOne receives a model and a query. Will return a single model that satifies the query.
func (*Manager) RawQuery ¶ added in v0.4.3
func (m *Manager) RawQuery(mList interface{}, model interfaces.Model, query ...string) error
RawQuery receives a model and a raw query. Will return all models that satisfies the raw query.
func (*Manager) Stage ¶
func (m *Manager) Stage(model interfaces.Model, operation string) error
Stage setups a model for changes, no change will be applied until State.Commit() is run
func (*Manager) ToggleLogs ¶ added in v0.3.2
func (m *Manager) ToggleLogs()
ToggleLogs enables or disables detailed logs