models

package
v0.0.39 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter added in v0.0.39

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

Adapter is adapter for mongo

type Base

type Base struct {
	ID        primitive.ObjectID `bson:"_id" json:"id"`
	CreatedAt time.Time          `bson:"created_at"`
	UpdatedAt time.Time          `bson:"updated_at"`
	// contains filtered or unexported fields
}

Base used to represent base classes for all models

func (*Base) Cache added in v0.0.39

func (base *Base) Cache()

func (*Base) Destroy added in v0.0.39

func (base *Base) Destroy() error

Destroy used to delete record from database

func (*Base) GetCollectionName added in v0.0.26

func (base *Base) GetCollectionName() string

GetCollectionName used to retrieve collection's name

func (*Base) GetHooksHandler added in v0.0.39

func (base *Base) GetHooksHandler() *HooksHandler

GetHooksHandler used to retrieve hooks handler

func (*Base) GetID

func (base *Base) GetID() string

GetID used to retrieve record's ID

func (*Base) Initialize added in v0.0.21

func (base *Base) Initialize(collection *Collection, hooksHandler *HooksHandler, item Modellable)

Initialize used for setting up base attributes for a mongo record

func (*Base) IsNewRecord added in v0.0.39

func (base *Base) IsNewRecord() bool

IsNewRecord used to check if record is new unsaved record

func (*Base) Reload added in v0.0.39

func (base *Base) Reload() error

Reload used to reload record from database

func (*Base) Save added in v0.0.39

func (base *Base) Save() error

Save used to save record in adapter

type Collection

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

Collection used to contain models

func (*Collection) Create

func (collection *Collection) Create(values helpers.H) (Modellable, error)

Create used to create item

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() *Query

Query returns query wrapper for retrieving records in adapter

type CollectionCacher added in v0.0.39

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

func (*CollectionCacher) Count added in v0.0.39

func (cacher *CollectionCacher) Count() int

Count used to count items

func (*CollectionCacher) Find added in v0.0.39

func (cacher *CollectionCacher) Find(predicate FindPredicate) Modellable

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

func (*CollectionCacher) FindAll added in v0.0.39

func (cacher *CollectionCacher) FindAll(predicate FindPredicate) []Modellable

FindAll used to find items in collection

func (*CollectionCacher) FindByID added in v0.0.39

func (cacher *CollectionCacher) FindByID(id string) Modellable

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

func (*CollectionCacher) First added in v0.0.39

func (cacher *CollectionCacher) First() Modellable

First used to return first item in collection

func (*CollectionCacher) GetItems added in v0.0.39

func (cacher *CollectionCacher) GetItems() []Modellable

GetItems used to return all items in collections

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) RegisterAfterInitializeHook added in v0.0.39

func (handler *HooksHandler) RegisterAfterInitializeHook(afterInitializeHook func(*helpers.Dictionary))

RegisterAfterInitializeHook used to add after initialize hook

func (*HooksHandler) RegisterValidationHook added in v0.0.39

func (handler *HooksHandler) RegisterValidationHook(validationHook func() error)

RegisterValidationHook used to add a validation hook

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) CreateCollection added in v0.0.23

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

CreateCollection used to create a collection for models manager

func (*Manager) RegisterAdapter added in v0.0.39

func (manager *Manager) RegisterAdapter(uri string, database string) error

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 {
	Initialize(*Collection, *HooksHandler, Modellable)
	Save() error
	GetID() string
	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 Query added in v0.0.39

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

Query is a wrapper for querying mongo

func (*Query) Count added in v0.0.39

func (query *Query) Count() (int64, error)

Count used to count records in collection with matching criterion

func (*Query) DestroyAll added in v0.0.39

func (query *Query) DestroyAll() error

func (*Query) Each added in v0.0.39

func (query *Query) Each(handler func(Modellable, error)) error

Each used to iterate record in collection with matching criterion

func (*Query) Find added in v0.0.39

func (query *Query) Find(id string) (Modellable, error)

func (*Query) First added in v0.0.39

func (query *Query) First() (Modellable, error)

First used to return first record in collection with matching criterion

func (*Query) FirstOrCreate added in v0.0.39

func (query *Query) FirstOrCreate(values helpers.H) (Modellable, error)

func (*Query) Where added in v0.0.39

func (query *Query) Where(filters bson.M) *Query

Where used to query collection

type Queryable added in v0.0.39

type Queryable interface {
	Where(filter helpers.H)
	Count() (int64, error)
}

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

type StateHandler

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

StateHandler used to

Jump to

Keyboard shortcuts

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