Documentation ¶
Overview ¶
Package eventstore provides a Store which manage models
Index ¶
- Constants
- Variables
- func DefaultDecode(data []byte, value interface{}) error
- func DefaultEncode(value interface{}) ([]byte, error)
- func NewSimpleTx(ds datastore.Datastore) datastore.Txn
- type Action
- type ActionType
- type Comparer
- type Config
- type Criterion
- func (c *Criterion) Eq(value interface{}) *Query
- func (c *Criterion) Fn(mf MatchFunc) *Query
- func (c *Criterion) Ge(value interface{}) *Query
- func (c *Criterion) Gt(value interface{}) *Query
- func (c *Criterion) Le(value interface{}) *Query
- func (c *Criterion) Lt(value interface{}) *Query
- func (c *Criterion) Ne(value interface{}) *Query
- type Datastore
- type DecodeFunc
- type EncodeFunc
- type Index
- type IndexConfig
- type Indexer
- type JSONCriterion
- func (c *JSONCriterion) Eq(value interface{}) *JSONQuery
- func (c *JSONCriterion) Ge(value interface{}) *JSONQuery
- func (c *JSONCriterion) Gt(value interface{}) *JSONQuery
- func (c *JSONCriterion) Le(value interface{}) *JSONQuery
- func (c *JSONCriterion) Lt(value interface{}) *JSONQuery
- func (c *JSONCriterion) Ne(value interface{}) *JSONQuery
- type JSONOperation
- type JSONQuery
- type JSONSort
- type JSONValue
- type ListenActionType
- type ListenOption
- type Listener
- type LocalEventListener
- type Manager
- type MarshaledResult
- type MatchFunc
- type Model
- func (m *Model) AddIndex(path string, unique bool) error
- func (m *Model) BaseKey() ds.Key
- func (m *Model) Create(vs ...interface{}) error
- func (m *Model) Delete(ids ...core.EntityID) error
- func (m *Model) Find(result interface{}, q *Query) error
- func (m *Model) FindByID(id core.EntityID, v interface{}) error
- func (m *Model) FindJSON(q *JSONQuery) (ret []string, err error)
- func (m *Model) Has(ids ...core.EntityID) (exists bool, err error)
- func (m *Model) Indexes() map[string]Index
- func (m *Model) ReadTxn(f func(txn *Txn) error) error
- func (m *Model) Save(vs ...interface{}) error
- func (m *Model) WriteTxn(f func(txn *Txn) error) error
- type Option
- type Query
- type Reducer
- type ServiceBoostrapper
- type ServiceConfig
- type ServiceOption
- type SimpleTx
- func (bt *SimpleTx) Commit() error
- func (bt *SimpleTx) Delete(key datastore.Key) error
- func (bt *SimpleTx) Discard()
- func (bt *SimpleTx) Get(k datastore.Key) ([]byte, error)
- func (bt *SimpleTx) GetSize(k datastore.Key) (int, error)
- func (bt *SimpleTx) Has(k datastore.Key) (bool, error)
- func (bt *SimpleTx) Put(key datastore.Key, val []byte) error
- func (bt *SimpleTx) Query(q query.Query) (query.Results, error)
- type Store
- func (s *Store) Close() error
- func (s *Store) GetModel(name string) *Model
- func (s *Store) Listen(los ...ListenOption) (Listener, error)
- func (s *Store) Reduce(events []core.Event) error
- func (s *Store) Register(name string, defaultInstance interface{}) (*Model, error)
- func (s *Store) RegisterSchema(name string, schema string, indexes ...*IndexConfig) (*Model, error)
- func (s *Store) Service() service.Service
- func (s *Store) Start() error
- func (s *Store) StartFromAddr(addr ma.Multiaddr, followKey, readKey *symmetric.Key) error
- func (s *Store) ThreadID() (thread.ID, bool, error)
- type TxMapDatastore
- type Txn
- func (t *Txn) Commit() error
- func (t *Txn) Create(new ...interface{}) error
- func (t *Txn) Delete(ids ...core.EntityID) error
- func (t *Txn) Discard()
- func (t *Txn) Find(res interface{}, q *Query) error
- func (t *Txn) FindByID(id core.EntityID, v interface{}) error
- func (t *Txn) FindJSON(q *JSONQuery) ([]string, error)
- func (t *Txn) Has(ids ...core.EntityID) (bool, error)
- func (t *Txn) Save(updated ...interface{}) error
Constants ¶
const ( // Eq is "equals" Eq = JSONOperation(eq) // Ne is "not equal to" Ne = JSONOperation(ne) // Gt is "greater than" Gt = JSONOperation(gt) // Lt is "less than" Lt = JSONOperation(lt) // Ge is "greater than or equal to" Ge = JSONOperation(ge) // Le is "less than or equal to" Le = JSONOperation(le) )
Variables ¶
var ( ErrUniqueExists = errors.New("unique constraint violation") ErrNotIndexable = errors.New("value not indexable") ErrNoIndexFound = errors.New("no index found") )
ErrUniqueExists is the error thrown when data is being inserted for a unique constraint value that already exists
var ( // ErrNotFound indicates that the specified instance doesn't // exist in the model. ErrNotFound = errors.New("instance not found") // ErrReadonlyTx indicates that no write operations can be done since // the current transaction is readonly. ErrReadonlyTx = errors.New("read only transaction") // ErrInvalidSchemaInstance indicates the current operation is from an // instance that doesn't satisfy the model schema. ErrInvalidSchemaInstance = errors.New("instance doesn't correspond to schema") )
var ( // ErrInvalidSortingField is returned when a query sorts a result by a // non-existent field in the model schema. ErrInvalidSortingField = errors.New("sorting field doesn't correspond to instance type") // ErrInvalidSliceType is returned when a query receives a result by a // slice type which doesn't correspond to the model being queried. ErrInvalidSliceType = errors.New("slice type doesn't correspond to model type") )
var ( // ErrInvalidModel indicates that the registered model isn't valid, // most probably doesn't have an EntityID.ID field. ErrInvalidModel = errors.New("the model is invalid") // ErrInvalidModelType indicates the provided default type isn't compatible // with a Model type. ErrInvalidModelType = errors.New("the model type should be a non-nil pointer to a struct") )
Functions ¶
func DefaultDecode ¶ added in v0.1.6
DefaultDecode is the default decoding func from badgerhold (Gob)
func DefaultEncode ¶ added in v0.1.6
DefaultEncode is the default encoding func from badgerhold (Gob)
Types ¶
type ActionType ¶
type ActionType int
const ( ActionCreate ActionType = iota + 1 ActionSave ActionDelete )
type Comparer ¶
Comparer compares a type against the encoded value in the store. The result should be 0 if current==other, -1 if current < other, and +1 if current > other. If a field in a struct doesn't specify a comparer, then the default comparison is used (convert to string and compare) this interface is already handled for standard Go Types as well as more complex ones such as those in time and big an error is returned if the type cannot be compared The concrete type will always be passedin, not a pointer
type Config ¶
type Config struct { RepoPath string Datastore ds.TxnDatastore EventCodec core.EventCodec JsonMode bool Debug bool LowMem bool }
Config has configuration parameters for a store
type Criterion ¶
type Criterion struct {
// contains filtered or unexported fields
}
Criterion is a partial condition that can specify comparison operator for a field.
type Datastore ¶
type Datastore struct { kt.KeyTransform ds.Datastore // contains filtered or unexported fields }
Datastore keeps a KeyTransform function
type DecodeFunc ¶ added in v0.1.6
DecodeFunc is a function for decoding a value from bytes
type EncodeFunc ¶ added in v0.1.6
EncodeFunc is a function for encoding a value into bytes
type Index ¶ added in v0.1.6
Index is a function that returns the indexable, encoded bytes of the passed in bytes
type IndexConfig ¶ added in v0.1.6
IndexConfig stores the configuration for a given Index.
type Indexer ¶ added in v0.1.6
Indexer is the interface to implement to support Model property indexes
type JSONCriterion ¶
type JSONCriterion struct { FieldPath string Operation JSONOperation Value JSONValue // contains filtered or unexported fields }
JSONCriterion represents a restriction on a field
func JSONWhere ¶
func JSONWhere(field string) *JSONCriterion
JSONWhere starts to create a query condition for a field
func (*JSONCriterion) Eq ¶
func (c *JSONCriterion) Eq(value interface{}) *JSONQuery
Eq is an equality operator against a field
func (*JSONCriterion) Ge ¶
func (c *JSONCriterion) Ge(value interface{}) *JSONQuery
Ge is a greater or equal operator against a field
func (*JSONCriterion) Gt ¶
func (c *JSONCriterion) Gt(value interface{}) *JSONQuery
Gt is a greater operator against a field
func (*JSONCriterion) Le ¶
func (c *JSONCriterion) Le(value interface{}) *JSONQuery
Le is a less or equal operator against a field
func (*JSONCriterion) Lt ¶
func (c *JSONCriterion) Lt(value interface{}) *JSONQuery
Lt is a less operation against a field
func (*JSONCriterion) Ne ¶
func (c *JSONCriterion) Ne(value interface{}) *JSONQuery
Ne is a not equal operator against a field
type JSONQuery ¶
type JSONQuery struct { Ands []*JSONCriterion Ors []*JSONQuery Sort JSONSort Index string }
JSONQuery is a json-seriable query representation
func JSONOrderBy ¶
JSONOrderBy specify ascending order for the query results.
func JSONOrderByDesc ¶
JSONOrderByDesc specify descending order for the query results.
func (*JSONQuery) JSONAnd ¶
func (q *JSONQuery) JSONAnd(field string) *JSONCriterion
JSONAnd concatenates a new condition in an existing field.
func (*JSONQuery) JSONOr ¶
JSONOr concatenates a new condition that is sufficient for an instance to satisfy, independant of the current Query. Has left-associativity as: (a And b) Or c
func (*JSONQuery) JSONOrderBy ¶
JSONOrderBy specify ascending order for the query results. On multiple calls, only the last one is considered.
func (*JSONQuery) JSONOrderByDesc ¶
JSONOrderByDesc specify descending order for the query results. On multiple calls, only the last one is considered.
type ListenActionType ¶
type ListenActionType int
const ( ListenAll ListenActionType = iota ListenCreate ListenSave ListenDelete )
type ListenOption ¶
type ListenOption struct { Type ListenActionType Model string ID core.EntityID }
type LocalEventListener ¶
type LocalEventListener struct {
// contains filtered or unexported fields
}
LocalEventListener notifies about new locally generated ipld.Nodes results of transactions
func (*LocalEventListener) Channel ¶
func (l *LocalEventListener) Channel() <-chan format.Node
Channel returns an unbuffered channel to receive local events
func (*LocalEventListener) Discard ¶
func (l *LocalEventListener) Discard()
Discard indicates that no further events will be received and ready for being garbage collected
type Manager ¶
func NewManager ¶
NewManager hydrates stores from prefixes and starts them.
type MarshaledResult ¶ added in v0.1.6
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model contains instances of a schema, and provides operations for creating, updating, deleting, and quering them.
func (*Model) AddIndex ¶ added in v0.1.6
AddIndex creates a new index based on the given path string. Set unique to true if you want a unique constraint on the given path. See https://github.com/tidwall/gjson for documentation on the supported path structure. Adding an index will override any overlapping index values if they already exist. @note: This does NOT currently build the index. If items have been added prior to adding a new index, they will NOT be indexed a posteriori.
func (*Model) Delete ¶
Delete deletes instances by its IDs. It doesn't fail if the ID doesn't exist.
func (*Model) FindByID ¶
FindByID finds an instance by its ID and saves it in v. If doesn't exists returns ErrNotFound.
func (*Model) ReadTxn ¶
ReadTxn creates an explicit readonly transaction. Any operation that tries to mutate an instance of the model will ErrReadonlyTx. Provides serializable isolation gurantees.
type Option ¶
Option takes a Config and modifies it
func WithEventCodec ¶
func WithEventCodec(ec core.EventCodec) Option
WithEventCodec configure to use ec as the EventCodec manager for transforming actions in events, and viceversa
func WithJsonMode ¶
func WithLowMem ¶ added in v0.1.10
func WithRepoPath ¶
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query allows to build queries to fetch data from a model.
func OrderByDesc ¶
OrderByDesc specify descending order for the query results.
func (*Query) Or ¶
Or concatenates a new condition that is sufficient for an instance to satisfy, independent of the current Query. Has left-associativity as: (a And b) Or c
func (*Query) OrderBy ¶
OrderBy specify ascending order for the query results. On multiple calls, only the last one is considered.
func (*Query) OrderByDesc ¶
OrderByDesc specify descending order for the query results. On multiple calls, only the last one is considered.
type ServiceBoostrapper ¶
type ServiceBoostrapper interface { coreservice.Service GetIpfsLite() *ipfslite.Peer Bootstrap(addrs []peer.AddrInfo) }
DefaultService is a boostrapable default Service with sane defaults.
func DefaultService ¶
func DefaultService(repoPath string, opts ...ServiceOption) (ServiceBoostrapper, error)
type ServiceConfig ¶
type ServiceConfig struct { HostAddr ma.Multiaddr Debug bool GRPCOptions []grpc.ServerOption }
type ServiceOption ¶
type ServiceOption func(c *ServiceConfig) error
func WithServiceDebug ¶
func WithServiceDebug(enabled bool) ServiceOption
func WithServiceGRPCOptions ¶ added in v0.1.6
func WithServiceGRPCOptions(opts ...grpc.ServerOption) ServiceOption
func WithServiceHostAddr ¶
func WithServiceHostAddr(addr ma.Multiaddr) ServiceOption
type SimpleTx ¶
type SimpleTx struct {
// contains filtered or unexported fields
}
SimpleTx implements the transaction interface for datastores who do not have any sort of underlying transactional support
type Store ¶
Store is the aggregate-root of events and state. External/remote events are dispatched to the Store, and are internally processed to impact model states. Likewise, local changes in models registered produce events dispatched externally.
func NewStore ¶
NewStore creates a new Store, which will *own* ds and dispatcher for internal use. Saying it differently, ds and dispatcher shouldn't be used externally.
func (*Store) Listen ¶
func (s *Store) Listen(los ...ListenOption) (Listener, error)
Listen returns a Listener which notifies about actions applying the defined filters. The Store *won't* wait for slow receivers, so if the channel is full, the action will be dropped.
func (*Store) RegisterSchema ¶
RegisterSchema a new model in the store with a JSON schema.
func (*Store) Start ¶
Start should be called immediatelly after registering all schemas and before any operation on them. If the store already boostraped on a thread, it will continue using that thread. In the opposite case, it will create a new thread.
func (*Store) StartFromAddr ¶
StartFromAddr should be called immediatelly after registering all schemas and before any operation on them. It pulls the current Store thread from thread addr
type TxMapDatastore ¶
type TxMapDatastore struct { *datastore.MapDatastore // contains filtered or unexported fields }
func NewTxMapDatastore ¶
func NewTxMapDatastore() *TxMapDatastore
func (*TxMapDatastore) NewTransaction ¶
func (d *TxMapDatastore) NewTransaction(readOnly bool) (datastore.Txn, error)
type Txn ¶
type Txn struct {
// contains filtered or unexported fields
}
Txn represents a read/write transaction in the Store. It allows for serializable isolation level within the store.
func (*Txn) Commit ¶
Commit applies all changes done in the current transaction to the model. This is a syncrhonous call so changes can be assumed to be applied on function return.
func (*Txn) Create ¶
Create creates new instances in the model If the ID value on the instance is nil or otherwise a null value (e.g., "" in jsonMode), the ID is updated in-place to reflect the automatically-genereted UUID.
func (*Txn) Discard ¶
func (t *Txn) Discard()
Discard discards all changes done in the current transaction.
func (*Txn) Find ¶
Find executes a query and store the result in res which should be a slice of pointers with the correct model type. If the slice isn't empty, will be emptied.