models

package
v1.0.82 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const StatusError = "error"

StatusError used to represent errored query or operation

View Source
const StatusSuccess = "success"

StatusSuccess used to represent success query or operation

Variables

This section is empty.

Functions

func Options

func Options() *options

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) Clear added in v1.0.60

func (belongsTo *BelongsTo) Clear() error

Clear used to clear association

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

func (belongsTo *BelongsTo) IsEmpty() bool

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

func (belongsTo *BelongsTo) Key() string

Key used to retrieve association's reference key

func (*BelongsTo) Set added in v1.0.60

func (belongsTo *BelongsTo) Set(item Modellable) error

Set used to set association

func (*BelongsTo) SetKey

func (belongsTo *BelongsTo) SetKey(key string) error

SetKey used to set association's reference key

func (*BelongsTo) WithForeignKey

func (belongsTo *BelongsTo) WithForeignKey(foreignKey string) *BelongsTo

WithForeignKey used to set belongs_to foreign key

func (*BelongsTo) WithPrimaryKey added in v1.0.12

func (belongsTo *BelongsTo) WithPrimaryKey(primaryKey string) *BelongsTo

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 MakeList

func MakeList(items ...Modellable) *List

MakeList used to instantiate list instance

func MakeListWithCollection added in v1.0.23

func MakeListWithCollection(collection *Collection, items ...Modellable) *List

MakeListWithCollection used to instantiate list instance with collection

func (*List) Add

func (list *List) Add(item Modellable)

Add used to store item to list

func (*List) Count

func (list *List) Count() int

Count used to count items

func (*List) Create added in v1.0.23

func (list *List) Create(attributes helpers.H) Modellable

Create used to create one instance

func (*List) Destroy added in v1.0.35

func (list *List) Destroy(id string) error

Destroy used to remove item from list

func (*List) Each added in v1.0.22

func (list *List) Each(handler func(Modellable) bool) error

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) FindIndex added in v1.0.35

func (list *List) FindIndex(id string) int

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

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

Adapter used to retrieve registered adapter

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

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

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

func (*Manager) Setup

func (manager *Manager) Setup()

Setup used to setup manager

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 NewHandler

type NewHandler func(*Context)

NewHandler is alias for func(*Context)

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) NotFound added in v1.0.63

func (result *SingleResult) NotFound() bool

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

type Validator

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