manager

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INSERT = "insert"
	UPDATE = "update"
	DELETE = "delete"
)

Operation codes

View Source
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) Applied

func (m *Manager) Applied() []*Change

Applied returns the previous list of applied changes

func (*Manager) Clear

func (m *Manager) Clear()

Clear deletes the list of staged chanbes

func (*Manager) Commit

func (m *Manager) Commit() error

Commit applies all of the staged changes

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) Rollback

func (m *Manager) Rollback() error

Rollback reverts the latest applied changes for the insert operation

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) Status

func (m *Manager) Status() []*Change

Status returns the current list of staged changes

func (*Manager) ToggleLogs added in v0.3.2

func (m *Manager) ToggleLogs()

ToggleLogs enables or disables detailed logs

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL