Versions in this module Expand all Collapse all v1 v1.0.1 Oct 17, 2020 Changes in this version + const Eq + const Ge + const Gt + const Le + const Lt + const Ne + var ErrCannotIndexIDField = errors.New("cannot create custom index on " + idFieldName) + var ErrCantCreateUniqueIndex = errors.New("can't create unique index (duplicate instances exist)") + var ErrCollectionAlreadyRegistered = errors.New("collection already registered") + var ErrCollectionNotFound = errors.New("collection not found") + var ErrDBExists = errors.New("db already exists") + var ErrDBNotFound = errors.New("db not found") + var ErrIndexNotFound = errors.New("index not found") + var ErrInstanceNotFound = errors.New("instance not found") + var ErrInvalidCollectionSchema = errors.New("the collection schema should specify an _id string property") + var ErrInvalidCollectionSchemaPath = errors.New("collection schema does not contain path") + var ErrInvalidName = errors.New(...) + var ErrInvalidSchemaInstance = errors.New("instance doesn't correspond to schema") + var ErrInvalidSortingField = errors.New("sorting field doesn't correspond to instance type") + var ErrNotIndexable = errors.New("value not indexable") + var ErrReadonlyTx = errors.New("read only transaction") + var ErrUniqueExists = errors.New("unique constraint violation") + func DefaultDecode(data []byte, value interface{}) error + func DefaultEncode(value interface{}) ([]byte, error) + func NewSimpleTx(ds datastore.Datastore) datastore.Txn + type Action struct + Collection string + ID core.InstanceID + Type ActionType + type ActionType int + const ActionCreate + const ActionDelete + const ActionSave + type Collection struct + func (c *Collection) Create(v []byte, opts ...TxnOption) (id core.InstanceID, err error) + func (c *Collection) CreateMany(vs [][]byte, opts ...TxnOption) (ids []core.InstanceID, err error) + func (c *Collection) Delete(id core.InstanceID, opts ...TxnOption) error + func (c *Collection) DeleteMany(ids []core.InstanceID, opts ...TxnOption) error + func (c *Collection) Find(q *Query, opts ...TxnOption) (instances [][]byte, err error) + func (c *Collection) FindByID(id core.InstanceID, opts ...TxnOption) (instance []byte, err error) + func (c *Collection) GetIndexes() []Index + func (c *Collection) GetName() string + func (c *Collection) GetReadFilter() []byte + func (c *Collection) GetSchema() []byte + func (c *Collection) GetWriteValidator() []byte + func (c *Collection) Has(id core.InstanceID, opts ...TxnOption) (exists bool, err error) + func (c *Collection) HasMany(ids []core.InstanceID, opts ...TxnOption) (exists bool, err error) + func (c *Collection) ReadTxn(f func(txn *Txn) error, opts ...TxnOption) error + func (c *Collection) Save(v []byte, opts ...TxnOption) error + func (c *Collection) SaveMany(vs [][]byte, opts ...TxnOption) error + func (c *Collection) Verify(v []byte, opts ...TxnOption) error + func (c *Collection) VerifyMany(vs [][]byte, opts ...TxnOption) error + func (c *Collection) WriteTxn(f func(txn *Txn) error, opts ...TxnOption) error + type CollectionConfig struct + Indexes []Index + Name string + ReadFilter string + Schema *jsonschema.Schema + WriteValidator string + type Comparer interface + Compare func(other interface{}) (int, error) + type Criterion struct + FieldPath string + Operation Operation + Value Value + func Where(field string) *Criterion + func (c *Criterion) Eq(value interface{}) *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 + func (c *Criterion) Validate() error + type DB struct + func NewDB(ctx context.Context, network app.Net, id thread.ID, opts ...NewOption) (*DB, error) + func NewDBFromAddr(ctx context.Context, network app.Net, addr ma.Multiaddr, key thread.Key, ...) (*DB, error) + func (d *DB) Close() error + func (d *DB) DeleteCollection(name string, opts ...Option) error + func (d *DB) GetCollection(name string, opts ...Option) *Collection + func (d *DB) GetDBInfo(opts ...Option) (info Info, err error) + func (d *DB) HandleNetRecord(ctx context.Context, rec net.ThreadRecord, key thread.Key) error + func (d *DB) ListCollections(opts ...Option) []*Collection + func (d *DB) Listen(los ...ListenOption) (Listener, error) + func (d *DB) NewCollection(config CollectionConfig, opts ...Option) (*Collection, error) + func (d *DB) Reduce(events []core.Event) error + func (d *DB) UpdateCollection(config CollectionConfig, opts ...Option) (*Collection, error) + func (d *DB) ValidateNetRecordBody(_ context.Context, body format.Node, identity thread.PubKey) error + type Datastore struct + func (d *Datastore) NewTransaction(readOnly bool) (ds.Txn, error) + type DecodeFunc func(data []byte, value interface{}) error + type EncodeFunc func(value interface{}) ([]byte, error) + type Index struct + Path string + Unique bool + type Info struct + Addrs []ma.Multiaddr + Key thread.Key + Name string + type ListenActionType int + const ListenAll + const ListenCreate + const ListenDelete + const ListenSave + type ListenOption struct + Collection string + ID core.InstanceID + Type ListenActionType + type Listener interface + Channel func() <-chan Action + Close func() + type ManagedOption func(*ManagedOptions) + func WithManagedToken(t thread.Token) ManagedOption + type ManagedOptions struct + Token thread.Token + type Manager struct + func NewManager(network app.Net, opts ...NewOption) (*Manager, error) + func (m *Manager) Close() error + func (m *Manager) DeleteDB(ctx context.Context, id thread.ID, opts ...ManagedOption) error + func (m *Manager) GetDB(ctx context.Context, id thread.ID, opts ...ManagedOption) (*DB, error) + func (m *Manager) GetToken(ctx context.Context, identity thread.Identity) (thread.Token, error) + func (m *Manager) ListDBs(ctx context.Context, opts ...ManagedOption) (map[thread.ID]*DB, error) + func (m *Manager) Net() net.Net + func (m *Manager) NewDB(ctx context.Context, id thread.ID, opts ...NewManagedOption) (*DB, error) + func (m *Manager) NewDBFromAddr(ctx context.Context, addr ma.Multiaddr, key thread.Key, ...) (*DB, error) + type MarshaledResult struct + MarshaledValue map[string]interface{} + type MatchFunc func(value interface{}) (bool, error) + type NewManagedOption func(*NewManagedOptions) + func WithNewManagedBackfillBlock(block bool) NewManagedOption + func WithNewManagedCollections(cs ...CollectionConfig) NewManagedOption + func WithNewManagedLogKey(key crypto.Key) NewManagedOption + func WithNewManagedName(name string) NewManagedOption + func WithNewManagedThreadKey(key thread.Key) NewManagedOption + func WithNewManagedToken(t thread.Token) NewManagedOption + type NewManagedOptions struct + Block bool + Collections []CollectionConfig + LogKey crypto.Key + Name string + ThreadKey thread.Key + Token thread.Token + type NewOption func(*NewOptions) + func WithNewBackfillBlock(block bool) NewOption + func WithNewCollections(cs ...CollectionConfig) NewOption + func WithNewDebug(enable bool) NewOption + func WithNewEventCodec(ec core.EventCodec) NewOption + func WithNewLogKey(key crypto.Key) NewOption + func WithNewLowMem(low bool) NewOption + func WithNewName(name string) NewOption + func WithNewRepoPath(path string) NewOption + func WithNewThreadKey(key thread.Key) NewOption + func WithNewToken(t thread.Token) NewOption + type NewOptions struct + Block bool + Collections []CollectionConfig + Datastore ds.TxnDatastore + Debug bool + EventCodec core.EventCodec + LogKey crypto.Key + LowMem bool + Name string + RepoPath string + ThreadKey thread.Key + Token thread.Token + type Operation int + type Option func(*Options) + func WithToken(t thread.Token) Option + type Options struct + Token thread.Token + type Query struct + Ands []*Criterion + Index string + Limit int + Ors []*Query + Seek core.InstanceID + Skip int + Sort Sort + func OrderBy(field string) *Query + func OrderByDesc(field string) *Query + func OrderByID() *Query + func OrderByIDDesc() *Query + func (q *Query) And(field string) *Criterion + func (q *Query) LimitTo(limit int) *Query + func (q *Query) Or(orQuery *Query) *Query + func (q *Query) OrderBy(field string) *Query + func (q *Query) OrderByDesc(field string) *Query + func (q *Query) OrderByID() *Query + func (q *Query) OrderByIDDesc() *Query + func (q *Query) SeekID(id core.InstanceID) *Query + func (q *Query) SkipNum(num int) *Query + func (q *Query) UseIndex(path string) *Query + func (q *Query) Validate() error + type Reducer interface + Reduce func(events []core.Event) error + type SimpleTx struct + 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 Sort struct + Desc bool + FieldPath string + type TxMapDatastore struct + func NewTxMapDatastore() *TxMapDatastore + func (d *TxMapDatastore) NewTransaction(_ bool) (datastore.Txn, error) + type Txn struct + func (t *Txn) Commit() error + func (t *Txn) Create(new ...[]byte) ([]core.InstanceID, error) + func (t *Txn) Delete(ids ...core.InstanceID) error + func (t *Txn) Discard() + func (t *Txn) Find(q *Query) ([][]byte, error) + func (t *Txn) FindByID(id core.InstanceID) ([]byte, error) + func (t *Txn) Has(ids ...core.InstanceID) (bool, error) + func (t *Txn) RefreshCollection() error + func (t *Txn) Save(updated ...[]byte) error + func (t *Txn) Verify(updated ...[]byte) error + type TxnOption func(*TxnOptions) + func WithTxnToken(t thread.Token) TxnOption + type TxnOptions struct + Token thread.Token + type Value struct + Bool *bool + Float *float64 + String *string