models

package
v0.0.66 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const StatusError = "error"

StatusError used to represent errored query or operation

View Source
const StatusNotFound = "notfound"

StatusNotFound used to represent not found query

View Source
const StatusSuccess = "success"

StatusSuccess used to represent success query or operation

Variables

This section is empty.

Functions

This section is empty.

Types

type Adaptable added in v0.0.46

type Adaptable interface {
	NewQuery(*Collection) Queryable
	RegisterCollection(string, *Collection)
	Collection(string) *Collection
	Collections() []*Collection
}

type Collection

type Collection struct {
	// contains filtered or unexported fields
}

Collection used to contain models

func (*Collection) Adapter added in v0.0.46

func (collection *Collection) Adapter() Adaptable

Adapter used to retrieve collection's adapter

func (*Collection) Create

func (collection *Collection) Create(values helpers.H) *SingleResult

Create used to create item

func (*Collection) List added in v0.0.51

func (collection *Collection) List() *List

List used to retrieve in-memory list

func (*Collection) Name added in v0.0.46

func (collection *Collection) Name() string

Name used to retrieve collection's name

func (*Collection) New added in v0.0.39

func (collection *Collection) New(values helpers.H) Modellable

New used to initialize item

func (*Collection) Query added in v0.0.39

func (collection *Collection) Query() Queryable

Query returns query wrapper for retrieving records in adapter

type CountResult added in v0.0.55

type CountResult struct {
	// contains filtered or unexported fields
}

CountResult used to wrap count records result from query

func MakeCountResult added in v0.0.55

func MakeCountResult() *CountResult

MakeCountResult used to instantiate count result

func (*CountResult) Count added in v0.0.55

func (result *CountResult) Count() int64

Count use to retrieve result's count

func (*CountResult) Set added in v0.0.55

func (result *CountResult) Set(count int64, err error)

Set used to set result count and error

func (*CountResult) Status added in v0.0.55

func (result *CountResult) Status() string

Status used to retrieve result's status

func (*CountResult) StatusError added in v0.0.57

func (result *CountResult) StatusError() bool

StatusError used to check if operation is errored

func (*CountResult) StatusSuccess added in v0.0.57

func (result *CountResult) StatusSuccess() bool

StatusSuccess used to check if operation is success

type FindPredicate added in v0.0.21

type FindPredicate func(Modellable) bool

FindPredicate is alias for func(Modellable) bool

type FiniteStateMachine

type FiniteStateMachine struct {
	// contains filtered or unexported fields
}

FiniteStateMachine used to implement fsm

func MakeFiniteStateMachine

func MakeFiniteStateMachine(defaultStateName string) *FiniteStateMachine

MakeFiniteStateMachine used to instantiate fsm

func (*FiniteStateMachine) AddStateHandler

func (fsm *FiniteStateMachine) AddStateHandler(
	stateName string,
	enterHandler func(string),
	runHandler func(),
	exitHandler func(),
)

AddStateHandler used to add handler for fsm's state

func (*FiniteStateMachine) Equals

func (fsm *FiniteStateMachine) Equals(stateName string) bool

Equals used to compare fsm's state

func (*FiniteStateMachine) GetActiveAgent

func (fsm *FiniteStateMachine) GetActiveAgent() interface{}

GetActiveAgent used to get fsm's active agent at current turn

func (*FiniteStateMachine) GetEndAt

func (fsm *FiniteStateMachine) GetEndAt() int64

GetEndAt used to get turn's end time

func (*FiniteStateMachine) GetName

func (fsm *FiniteStateMachine) GetName() string

GetName used to get fsm's state name

func (*FiniteStateMachine) GoTo

func (fsm *FiniteStateMachine) GoTo(stateName string, item Modellable)

GoTo used for fsm's state transition

func (*FiniteStateMachine) IsTurnExpired

func (fsm *FiniteStateMachine) IsTurnExpired() bool

IsTurnExpired used to check if turn is expired

func (*FiniteStateMachine) Run

func (fsm *FiniteStateMachine) Run(item Modellable)

Run used to run fsm's state

func (*FiniteStateMachine) SetTurn

func (fsm *FiniteStateMachine) SetTurn(activeAgent Modellable, endAt time.Time)

SetTurn used to set new turn

type HooksHandler added in v0.0.39

type HooksHandler struct {
	// contains filtered or unexported fields
}

HooksHandler used to mange callbacks for models

func (*HooksHandler) ExecuteAfterInstantiateHook added in v0.0.46

func (handler *HooksHandler) ExecuteAfterInstantiateHook()

ExecuteAfterInstantiateHook used to execute after instantiate hook

func (*HooksHandler) ExecuteAfterMemoizeHook added in v0.0.46

func (handler *HooksHandler) ExecuteAfterMemoizeHook()

ExecuteAfterMemoizeHook used to execute after memoize hook

func (*HooksHandler) ExecuteInitializeHook added in v0.0.46

func (handler *HooksHandler) ExecuteInitializeHook(values *helpers.Dictionary)

ExecuteInitializeHook used to execute after initialize hook

func (*HooksHandler) ExecuteValidationHooks added in v0.0.46

func (handler *HooksHandler) ExecuteValidationHooks() error

ExecuteValidationHooks used to execute validation hooks

func (*HooksHandler) RegisterAfterInstantiateHook added in v0.0.41

func (handler *HooksHandler) RegisterAfterInstantiateHook(afterInstantiateHook func())

RegisterAfterInstantiateHook used to add after instantiate hook

func (*HooksHandler) RegisterAfterMemoizeHook added in v0.0.42

func (handler *HooksHandler) RegisterAfterMemoizeHook(afterMemoizeHook func())

RegisterAfterMemoizeHook used to add after memoize hook

func (*HooksHandler) RegisterInitializeHook added in v0.0.40

func (handler *HooksHandler) RegisterInitializeHook(initializeHook func(*helpers.Dictionary))

RegisterInitializeHook used to add initialize hook

func (*HooksHandler) RegisterValidationHook added in v0.0.39

func (handler *HooksHandler) RegisterValidationHook(validationHook Validator)

RegisterValidationHook used to add a validation hook

type List added in v0.0.51

type List struct {
	// contains filtered or unexported fields
}

List is an in-memory storage of items

func (*List) Add added in v0.0.51

func (list *List) Add(item Modellable)

Add used to memoize item

func (*List) Count added in v0.0.51

func (list *List) Count() int

Count used to count items

func (*List) Find added in v0.0.51

func (list *List) Find(predicate FindPredicate) Modellable

Find used to find item in collection, return nil if not found

func (*List) FindAll added in v0.0.51

func (list *List) FindAll(predicate FindPredicate) []Modellable

FindAll used to find items in collection

func (*List) FindByID added in v0.0.51

func (list *List) FindByID(id string) Modellable

FindByID used to find item in collection by id, return nil if not found

func (*List) First added in v0.0.51

func (list *List) First() Modellable

First used to return first item in collection

func (*List) Items added in v0.0.51

func (list *List) Items() []Modellable

Items used to return all items in collections

type ListResults added in v0.0.55

type ListResults struct {
	// contains filtered or unexported fields
}

ListResults used to wrap multiple record results from query

func MakeListResults added in v0.0.55

func MakeListResults() *ListResults

MakeListResults used to instantiate list results

func (*ListResults) Error added in v0.0.59

func (results *ListResults) Error() error

func (*ListResults) Items added in v0.0.55

func (results *ListResults) Items() []Modellable

Items used to retrieve result's all items

func (*ListResults) Set added in v0.0.55

func (results *ListResults) Set(items []Modellable, err error)

Set used to set result's items and err

func (*ListResults) StatusError added in v0.0.57

func (results *ListResults) StatusError() bool

StatusError used to check if operation is errored

func (*ListResults) StatusSuccess added in v0.0.57

func (results *ListResults) StatusSuccess() bool

StatusSuccess used to check if operation is success

type Manager added in v0.0.22

type Manager struct {
	// contains filtered or unexported fields
}

Manager is a singleton used to manager model's behavior

func (*Manager) Adapter added in v0.0.46

func (manager *Manager) Adapter(clientName string) Adaptable

Adapter used to retrieve registered adapter

func (*Manager) Collection added in v0.0.66

func (manager *Manager) Collection(clientName string, collectionName string) *Collection

Collection used to retrieve registered collection

func (*Manager) CreateCollection added in v0.0.23

func (manager *Manager) CreateCollection(clientName string, collectionName string, newHandler NewHandler) *Collection

CreateCollection used to create a collection without registering

func (*Manager) RegisterAdapter added in v0.0.39

func (manager *Manager) RegisterAdapter(clientName string, adapter Adaptable)

RegisterAdapter used to register adapter

func (*Manager) RegisterCollection added in v0.0.22

func (manager *Manager) RegisterCollection(clientName string, collectionName string, newHandler NewHandler) *Collection

RegisterCollection used to create a collection and register with adapter

func (*Manager) Setup added in v0.0.22

func (manager *Manager) Setup()

Setup used to setup manager

type Modellable added in v0.0.21

type Modellable interface {
	InitializeBase(*Collection, *HooksHandler, Modellable)
	GetID() string
	Save() error
	Memoize()
	GetHooksHandler() *HooksHandler
}

Modellable is the interface for all models implementing model's functionalities

type NewHandler added in v0.0.39

type NewHandler func(*Collection, *HooksHandler) Modellable

NewHandler is alias for func(args ...interface{}) Modellable

type Queryable added in v0.0.39

type Queryable interface {
	Where(filter helpers.H) Queryable
	Count() *CountResult
	Each(func(Modellable, error) bool) error
	First() *SingleResult
	FirstOrCreate(helpers.H) *SingleResult
	Find(string) *SingleResult
	All() *ListResults
}

Queryable is the interface for all query adapter implementing query's functionalities

type SingleResult added in v0.0.55

type SingleResult struct {
	// contains filtered or unexported fields
}

SingleResult used to wrap single record result from query or create operation

func MakeSingleResult added in v0.0.55

func MakeSingleResult() *SingleResult

MakeSingleResult used to instantiate single result

func (*SingleResult) Error added in v0.0.55

func (result *SingleResult) Error() error

func (*SingleResult) ErrorMessage added in v0.0.55

func (result *SingleResult) ErrorMessage() string

ErrorMessage used to retrieve result's error message

func (*SingleResult) Item added in v0.0.55

func (result *SingleResult) Item() Modellable

Item used to retrieve result's item

func (*SingleResult) Set added in v0.0.55

func (result *SingleResult) Set(item Modellable, err error, notFound bool)

Set used to set result item, error and status

func (*SingleResult) Status added in v0.0.55

func (result *SingleResult) Status() string

Status used to retrieve result's status

func (*SingleResult) StatusError added in v0.0.57

func (result *SingleResult) StatusError() bool

StatusError used to check if operation is errored

func (*SingleResult) StatusNotFound added in v0.0.57

func (result *SingleResult) StatusNotFound() bool

StatusNotFound used to check if record is not found

func (*SingleResult) StatusSuccess added in v0.0.57

func (result *SingleResult) StatusSuccess() bool

StatusSuccess used to check if operation is success

type StateHandler

type StateHandler struct {
	// contains filtered or unexported fields
}

StateHandler used to

type Validator added in v0.0.57

type Validator func() error

Validator is alias for func(*Connection) (interface{}, error)

Jump to

Keyboard shortcuts

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