Documentation ¶
Index ¶
- Constants
- func Options() *options
- type Adaptable
- type AssociationsHandler
- type BelongsTo
- func (belongsTo *BelongsTo) Clear() error
- func (belongsTo *BelongsTo) Equals(item Modellable) bool
- func (belongsTo *BelongsTo) IsEmpty() bool
- func (belongsTo *BelongsTo) Item() Modellable
- func (belongsTo *BelongsTo) Key() string
- func (belongsTo *BelongsTo) Set(item Modellable) error
- func (belongsTo *BelongsTo) SetKey(key string) error
- func (belongsTo *BelongsTo) WithForeignKey(foreignKey string) *BelongsTo
- func (belongsTo *BelongsTo) WithPrimaryKey(primaryKey string) *BelongsTo
- type Collection
- func (collection *Collection) Adapter() Adaptable
- func (collection *Collection) Create(values helpers.H) *SingleResult
- func (collection *Collection) CreateWithOptions(values helpers.H, options *options) *SingleResult
- func (collection *Collection) List() *List
- func (collection *Collection) Name() string
- func (collection *Collection) New(values helpers.H) Modellable
- func (collection *Collection) Query() Queryable
- type Context
- func (context *Context) AssociationsHandler() *AssociationsHandler
- func (context *Context) Attributes() *helpers.Dictionary
- func (context *Context) Collection() *Collection
- func (context *Context) HooksHandler() *HooksHandler
- func (context *Context) Item() Modellable
- func (context *Context) SetItem(item Modellable)
- type CountResult
- type FindPredicate
- type FiniteStateMachine
- func (fsm *FiniteStateMachine) Equals(stateName string) bool
- func (fsm *FiniteStateMachine) GetActiveAgent() interface{}
- func (fsm *FiniteStateMachine) GetEndAt() int64
- func (fsm *FiniteStateMachine) GetName() string
- func (fsm *FiniteStateMachine) GoTo(stateName string, item Modellable)
- func (fsm *FiniteStateMachine) IsTurnExpired() bool
- func (fsm *FiniteStateMachine) RegisterState(stateName string) *StateHandler
- func (fsm *FiniteStateMachine) Run(item Modellable, dt float64)
- func (fsm *FiniteStateMachine) SetTurn(activeAgent Modellable, endAt time.Time)
- type HooksHandler
- func (handler *HooksHandler) ExecuteAfterCreateHooks()
- func (handler *HooksHandler) ExecuteDestroyHooks()
- func (handler *HooksHandler) ExecuteInitializeHook(values *helpers.Dictionary)
- func (handler *HooksHandler) ExecuteValidationHooks() error
- func (handler *HooksHandler) RegisterAfterCreateHook(afterCreateHook func())
- func (handler *HooksHandler) RegisterAfterDestroyHook(afterDestroyHook func())
- func (handler *HooksHandler) RegisterInitializeHook(initializeHook func(*helpers.Dictionary))
- func (handler *HooksHandler) RegisterValidationHook(validationHook Validator)
- type List
- func (list *List) Add(item Modellable)
- func (list *List) Count() int
- func (list *List) Create(attributes helpers.H) Modellable
- func (list *List) Destroy(id string) error
- func (list *List) Each(handler func(Modellable) bool) error
- func (list *List) Find(predicate FindPredicate) Modellable
- func (list *List) FindAll(predicate FindPredicate) *List
- func (list *List) FindByID(id string) Modellable
- func (list *List) FindIndex(id string) int
- func (list *List) First() Modellable
- func (list *List) FirstOrCreate(filters helpers.H) Modellable
- func (list *List) Items() []Modellable
- func (list *List) Sort(predicate SortPredictate) *List
- type ListResults
- type Manager
- func (manager *Manager) Adapter(clientName string) Adaptable
- func (manager *Manager) Collection(clientName string, collectionName string) *Collection
- func (manager *Manager) CreateCollection(clientName string, collectionName string, newHandler NewHandler) *Collection
- func (manager *Manager) RegisterAdapter(clientName string, adapter Adaptable)
- func (manager *Manager) RegisterCollection(clientName string, collectionName string, newHandler NewHandler) *Collection
- func (manager *Manager) Setup()
- type Modellable
- type NewHandler
- type Queryable
- type SingleResult
- func (result *SingleResult) Error() error
- func (result *SingleResult) ErrorMessage() string
- func (result *SingleResult) Item() Modellable
- func (result *SingleResult) Set(item Modellable, err error, notFound bool)
- func (result *SingleResult) Status() string
- func (result *SingleResult) StatusError() bool
- func (result *SingleResult) StatusNotFound() bool
- func (result *SingleResult) StatusSuccess() bool
- type SortPredictate
- type StateHandler
- type Validator
Constants ¶
const StatusError = "error"
StatusError used to represent errored query or operation
const StatusNotFound = "notfound"
StatusNotFound used to represent not found query
const StatusSuccess = "success"
StatusSuccess used to represent success query or operation
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Adaptable ¶
type Adaptable interface { NewQuery(*Collection) Queryable RegisterCollection(string, *Collection) Collection(string) *Collection Collections() []*Collection }
Adaptable is the interface for all adapters implementing adapter's functionalities
type AssociationsHandler ¶
type AssociationsHandler struct {
// contains filtered or unexported fields
}
func (*AssociationsHandler) RegisterBelongsTo ¶
func (handler *AssociationsHandler) RegisterBelongsTo(collection *Collection) *BelongsTo
type BelongsTo ¶
type BelongsTo struct {
// contains filtered or unexported fields
}
func (*BelongsTo) Equals ¶ added in v1.0.52
func (belongsTo *BelongsTo) Equals(item Modellable) bool
Equals used to compare if item is association
func (*BelongsTo) IsEmpty ¶ added in v1.0.47
IsEmpty used to determine if belongs_to association is empty
func (*BelongsTo) Item ¶
func (belongsTo *BelongsTo) Item() Modellable
Item used to retrieve association's item
func (*BelongsTo) Set ¶ added in v1.0.60
func (belongsTo *BelongsTo) Set(item Modellable) error
Set used to set association
func (*BelongsTo) WithForeignKey ¶
WithForeignKey used to set belongs_to foreign key
func (*BelongsTo) WithPrimaryKey ¶ added in v1.0.12
WithPrimaryKey used to set belongs_to primary key
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection used to contain models
func (*Collection) Adapter ¶
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) CreateWithOptions ¶
func (collection *Collection) CreateWithOptions(values helpers.H, options *options) *SingleResult
CreateWithOptions used to create item with options
func (*Collection) List ¶
func (collection *Collection) List() *List
List used to retrieve in-memory list
func (*Collection) Name ¶
func (collection *Collection) Name() string
Name used to retrieve collection's name
func (*Collection) New ¶
func (collection *Collection) New(values helpers.H) Modellable
New used to initialize item
func (*Collection) Query ¶
func (collection *Collection) Query() Queryable
Query returns query wrapper for retrieving records in adapter
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func (*Context) AssociationsHandler ¶
func (context *Context) AssociationsHandler() *AssociationsHandler
func (*Context) Attributes ¶
func (context *Context) Attributes() *helpers.Dictionary
func (*Context) Collection ¶
func (context *Context) Collection() *Collection
func (*Context) HooksHandler ¶
func (context *Context) HooksHandler() *HooksHandler
func (*Context) Item ¶
func (context *Context) Item() Modellable
func (*Context) SetItem ¶
func (context *Context) SetItem(item Modellable)
type CountResult ¶
type CountResult struct {
// contains filtered or unexported fields
}
CountResult used to wrap count records result from query
func MakeCountResult ¶
func MakeCountResult() *CountResult
MakeCountResult used to instantiate count result
func (*CountResult) Count ¶
func (result *CountResult) Count() int64
Count use to retrieve result's count
func (*CountResult) Set ¶
func (result *CountResult) Set(count int64, err error)
Set used to set result count and error
func (*CountResult) Status ¶
func (result *CountResult) Status() string
Status used to retrieve result's status
func (*CountResult) StatusError ¶
func (result *CountResult) StatusError() bool
StatusError used to check if operation is errored
func (*CountResult) StatusSuccess ¶
func (result *CountResult) StatusSuccess() bool
StatusSuccess used to check if operation is success
type FindPredicate ¶
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) 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) RegisterState ¶
func (fsm *FiniteStateMachine) RegisterState(stateName string) *StateHandler
RegisterState used to add handler for fsm's state
func (*FiniteStateMachine) Run ¶
func (fsm *FiniteStateMachine) Run(item Modellable, dt float64)
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 ¶
type HooksHandler struct {
// contains filtered or unexported fields
}
HooksHandler used to mange callbacks for models
func (*HooksHandler) ExecuteAfterCreateHooks ¶ added in v1.0.45
func (handler *HooksHandler) ExecuteAfterCreateHooks()
ExecuteAfterCreateHooks used to execute after create hooks
func (*HooksHandler) ExecuteDestroyHooks ¶ added in v1.0.45
func (handler *HooksHandler) ExecuteDestroyHooks()
ExecuteDestroyHooks used to execute after destroy hooks
func (*HooksHandler) ExecuteInitializeHook ¶
func (handler *HooksHandler) ExecuteInitializeHook(values *helpers.Dictionary)
ExecuteInitializeHook used to execute after initialize hook
func (*HooksHandler) ExecuteValidationHooks ¶
func (handler *HooksHandler) ExecuteValidationHooks() error
ExecuteValidationHooks used to execute validation hooks
func (*HooksHandler) RegisterAfterCreateHook ¶
func (handler *HooksHandler) RegisterAfterCreateHook(afterCreateHook func())
RegisterAfterCreateHook used to add after create hook
func (*HooksHandler) RegisterAfterDestroyHook ¶ added in v1.0.45
func (handler *HooksHandler) RegisterAfterDestroyHook(afterDestroyHook func())
RegisterAfterDestroyHook used to add after destroy hook
func (*HooksHandler) RegisterInitializeHook ¶
func (handler *HooksHandler) RegisterInitializeHook(initializeHook func(*helpers.Dictionary))
RegisterInitializeHook used to add initialize hook
func (*HooksHandler) RegisterValidationHook ¶
func (handler *HooksHandler) RegisterValidationHook(validationHook Validator)
RegisterValidationHook used to add a validation hook
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is an in-memory storage of items
func MakeListWithCollection ¶ added in v1.0.23
func MakeListWithCollection(collection *Collection, items ...Modellable) *List
MakeListWithCollection used to instantiate list instance with collection
func (*List) Create ¶ added in v1.0.23
func (list *List) Create(attributes helpers.H) Modellable
Create used to create one instance
func (*List) Find ¶
func (list *List) Find(predicate FindPredicate) Modellable
Find used to find item in collection, return nil if not found
func (*List) FindAll ¶
func (list *List) FindAll(predicate FindPredicate) *List
FindAll used to find items in collection
func (*List) FindByID ¶
func (list *List) FindByID(id string) Modellable
FindByID used to find item in collection by id, return nil if not found
func (*List) First ¶
func (list *List) First() Modellable
First used to return first item in collection
func (*List) FirstOrCreate ¶ added in v1.0.23
func (list *List) FirstOrCreate(filters helpers.H) Modellable
FirstOrCreate used to return first item in collection or create one
func (*List) Items ¶
func (list *List) Items() []Modellable
Items used to return all items in collections
func (*List) Sort ¶ added in v1.0.20
func (list *List) Sort(predicate SortPredictate) *List
Sort used to sort items in collection
type ListResults ¶
type ListResults struct {
// contains filtered or unexported fields
}
ListResults used to wrap multiple record results from query
func MakeListResults ¶
func MakeListResults() *ListResults
MakeListResults used to instantiate list results
func (*ListResults) Error ¶
func (results *ListResults) Error() error
func (*ListResults) List ¶
func (results *ListResults) List() *List
List used to retrieve result's list
func (*ListResults) Set ¶
func (results *ListResults) Set(list *List, err error)
Set used to set result's list and err
func (*ListResults) StatusError ¶
func (results *ListResults) StatusError() bool
StatusError used to check if operation is errored
func (*ListResults) StatusSuccess ¶
func (results *ListResults) StatusSuccess() bool
StatusSuccess used to check if operation is success
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is a singleton used to manager model's behavior
func (*Manager) Collection ¶
func (manager *Manager) Collection(clientName string, collectionName string) *Collection
Collection used to retrieve registered collection
func (*Manager) CreateCollection ¶
func (manager *Manager) CreateCollection(clientName string, collectionName string, newHandler NewHandler) *Collection
CreateCollection used to create a collection without registering
func (*Manager) RegisterAdapter ¶
RegisterAdapter used to register adapter
func (*Manager) RegisterCollection ¶
func (manager *Manager) RegisterCollection(clientName string, collectionName string, newHandler NewHandler) *Collection
RegisterCollection used to create a collection and register with adapter
type Modellable ¶
type Modellable interface { InitializeBase(*Context) GetID() string Save() error GetHooksHandler() *HooksHandler Store() StoreInList(*List) }
Modellable is the interface for all models implementing model's functionalities
type Queryable ¶
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 ToList() *ListResults Sort(string, bool) Queryable }
Queryable is the interface for all query adapter implementing query's functionalities
type SingleResult ¶
type SingleResult struct {
// contains filtered or unexported fields
}
SingleResult used to wrap single record result from query or create operation
func MakeSingleResult ¶
func MakeSingleResult() *SingleResult
MakeSingleResult used to instantiate single result
func (*SingleResult) Error ¶
func (result *SingleResult) Error() error
func (*SingleResult) ErrorMessage ¶
func (result *SingleResult) ErrorMessage() string
ErrorMessage used to retrieve result's error message
func (*SingleResult) Item ¶
func (result *SingleResult) Item() Modellable
Item used to retrieve result's item
func (*SingleResult) Set ¶
func (result *SingleResult) Set(item Modellable, err error, notFound bool)
Set used to set result item, error and status
func (*SingleResult) Status ¶
func (result *SingleResult) Status() string
Status used to retrieve result's status
func (*SingleResult) StatusError ¶
func (result *SingleResult) StatusError() bool
StatusError used to check if operation is errored
func (*SingleResult) StatusNotFound ¶
func (result *SingleResult) StatusNotFound() bool
StatusNotFound used to check if record is not found
func (*SingleResult) StatusSuccess ¶
func (result *SingleResult) StatusSuccess() bool
StatusSuccess used to check if operation is success
type SortPredictate ¶ added in v1.0.20
type SortPredictate func(Modellable, Modellable) bool
SortPredictate is alias for func(Modellable, Modellable) bool
type StateHandler ¶
type StateHandler struct {
// contains filtered or unexported fields
}
StateHandler used to handle fsm's callback
func (*StateHandler) WithEnterHook ¶
func (handler *StateHandler) WithEnterHook(hook func(string)) *StateHandler
WithEnterHook used to register state handler's enter hook
func (*StateHandler) WithExitHook ¶
func (handler *StateHandler) WithExitHook(hook func()) *StateHandler
WithExitHook used to register state handler's exit hook
func (*StateHandler) WithRunHook ¶
func (handler *StateHandler) WithRunHook(hook func(float64)) *StateHandler
WithRunHook used to register state handler's run hook