eventstore

package module
v0.0.0-...-2723bb6 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2019 License: MIT Imports: 19 Imported by: 0

README

DEPRECATED

This repository is DEPRECATED, all contents were moved to go-textile-threads.

go-eventstore

Made by Textile Chat on Slack GitHub license Go Report Card Go Doc Release CircleCI branch standard-readme compliant

A lightweight event store in Go

TODO: Fill out this long description.

Table of Contents

Background

Install

go get github.com/textileio/go-eventstore

Usage

Coming Soon

API

Coming Soon

Maintainers

Carson Farmer

Contributing

See the contributing file!

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © 2019 Textile.io

Documentation

Overview

MIT License

Copyright (c) 2019 Tim Shannon

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Code has multiple changes compared to original, but corresponds proper mentioning.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound              = errors.New("instance not found")
	ErrReadonlyTx            = errors.New("read only transaction")
	ErrInvalidSchemaInstance = errors.New("instance doesn't correspond to schema")
)
View Source
var (
	ErrInvalidSortingField = errors.New("sorting field doesn't correspond to instance type")
	ErrCantCompareOnSort   = errors.New("can't compare while sorting")
)
View Source
var (
	ErrInvalidModel = errors.New("the model is valid")
)

Functions

func NewSimpleTx

func NewSimpleTx(ds datastore.Datastore) datastore.Txn

func Where

func Where(field string) *criterion

Types

type Comparer

type Comparer interface {
	Compare(other interface{}) (int, error)
}

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 Dispatcher

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

Dispatcher is used to dispatch events to registered reducers.

This is different from generic pub-sub systems because reducers are not subscribed to particular events. Every event is dispatched to every registered reducer. When a given reducer is registered, it returns a `token`, which can be used to deregister the reducer later.

func NewDispatcher

func NewDispatcher(store datastore.TxnDatastore) *Dispatcher

NewDispatcher creates a new EventDispatcher

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(event core.Event) error

Dispatch dispatches a payload to all registered reducers.

func (*Dispatcher) Query

func (d *Dispatcher) Query(query query.Query) ([]query.Entry, error)

Query searches the internal event store and returns a query result. This is a syncronouse version of github.com/ipfs/go-datastore's Query method

func (*Dispatcher) Register

func (d *Dispatcher) Register(reducer Reducer)

Register takes a reducer to be invoked with each dispatched event

func (*Dispatcher) Store

func (d *Dispatcher) Store() datastore.TxnDatastore

Store returns the internal event store.

type MatchFunc

type MatchFunc func(value interface{}) (bool, error)

MatchFunc is a function used to test an arbitrary matching value in a query

type Model

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

func NewModel

func NewModel(name string, defaultInstance interface{}, datastore ds.Datastore, dispatcher *Dispatcher, eventcreator core.EventCodec, s *Store) *Model

func (*Model) Create

func (m *Model) Create(vs ...interface{}) error

func (*Model) Delete

func (m *Model) Delete(ids ...core.EntityID) error

func (*Model) Find

func (m *Model) Find(result interface{}, q *Query) error

func (*Model) FindByID

func (m *Model) FindByID(id core.EntityID, v interface{}) error

func (*Model) Has

func (m *Model) Has(ids ...core.EntityID) (exists bool, err error)

func (*Model) ReadTxn

func (m *Model) ReadTxn(f func(txn *Txn) error) error

func (*Model) Reduce

func (m *Model) Reduce(event core.Event) error

func (*Model) Save

func (m *Model) Save(vs ...interface{}) error

func (*Model) WriteTxn

func (m *Model) WriteTxn(f func(txn *Txn) error) error

type Query

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

func (*Query) And

func (q *Query) And(field string) *criterion

func (*Query) Or

func (q *Query) Or(orQuery *Query) *Query

func (*Query) OrderBy

func (q *Query) OrderBy(field string) *Query

func (*Query) OrderByDesc

func (q *Query) OrderByDesc(field string) *Query

type Reducer

type Reducer interface {
	Reduce(event core.Event) error
}

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

func (*SimpleTx) Commit

func (bt *SimpleTx) Commit() error

func (*SimpleTx) Delete

func (bt *SimpleTx) Delete(key datastore.Key) error

func (*SimpleTx) Discard

func (bt *SimpleTx) Discard()

func (*SimpleTx) Get

func (bt *SimpleTx) Get(k datastore.Key) ([]byte, error)

func (*SimpleTx) GetSize

func (bt *SimpleTx) GetSize(k datastore.Key) (int, error)

func (*SimpleTx) Has

func (bt *SimpleTx) Has(k datastore.Key) (bool, error)

func (*SimpleTx) Put

func (bt *SimpleTx) Put(key datastore.Key, val []byte) error

func (*SimpleTx) Query

func (bt *SimpleTx) Query(q query.Query) (query.Results, error)

type Store

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

func NewStore

func NewStore(ds ds.Datastore, dispatcher *Dispatcher, ec core.EventCodec) *Store

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

func (s *Store) Dispatch(e core.Event)

Dispatch applies external events to the store. This function guarantee no interference with registered model states, and viceversa.

func (*Store) Register

func (s *Store) Register(name string, defaultInstance interface{}) (*Model, error)

type TxMapDatastore

type TxMapDatastore struct {
	*datastore.MapDatastore
	// contains filtered or unexported fields
}

TxMapDatastore does stuff...

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

func (t *Txn) Commit() error

func (*Txn) Create

func (t *Txn) Create(new ...interface{}) error

Create creates new instances in the model

func (*Txn) Delete

func (t *Txn) Delete(ids ...core.EntityID) error

func (*Txn) Discard

func (t *Txn) Discard()

func (*Txn) Find

func (t *Txn) Find(res interface{}, q *Query) error

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.

func (*Txn) FindByID

func (t *Txn) FindByID(id core.EntityID, v interface{}) error

func (*Txn) Has

func (t *Txn) Has(ids ...core.EntityID) (bool, error)

func (*Txn) Save

func (t *Txn) Save(updated ...interface{}) error

Directories

Path Synopsis
Package broadcast implements multi-listener broadcast channels.
Package broadcast implements multi-listener broadcast channels.
e2e

Jump to

Keyboard shortcuts

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