Documentation ¶
Overview ¶
Package db provides a DB which manage collections
Index ¶
- Constants
- Variables
- func DefaultDecode(data []byte, value interface{}) error
- func DefaultEncode(value interface{}) ([]byte, error)
- func NewSimpleTx(store ds.Datastore) dse.TxnExt
- type Action
- type ActionType
- type Collection
- 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) ModifiedSince(time int64, opts ...TxnOption) (ids []core.InstanceID, 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
- type Comparer
- type 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
- 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 DecodeFunc
- type EncodeFunc
- type Index
- type Info
- type ListenActionType
- type ListenOption
- type Listener
- type ManagedOption
- type ManagedOptions
- type Manager
- 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
- type MatchFunc
- type NewManagedOption
- func WithNewManagedBackfillBlock(block bool) NewManagedOption
- func WithNewManagedCollections(cs ...CollectionConfig) NewManagedOption
- func WithNewManagedKey(key thread.Key) NewManagedOption
- func WithNewManagedLogKey(key crypto.Key) NewManagedOption
- func WithNewManagedName(name string) NewManagedOption
- func WithNewManagedToken(t thread.Token) NewManagedOption
- type NewManagedOptions
- type NewOption
- func WithNewBackfillBlock(block bool) NewOption
- func WithNewCollections(cs ...CollectionConfig) NewOption
- func WithNewDebug(enable bool) NewOption
- func WithNewEventCodec(ec core.EventCodec) NewOption
- func WithNewKey(key thread.Key) NewOption
- func WithNewLogKey(key crypto.Key) NewOption
- func WithNewName(name string) NewOption
- func WithNewToken(t thread.Token) NewOption
- type NewOptions
- type Operation
- type Option
- type Options
- type 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
- type SimpleTx
- func (bt *SimpleTx) Commit() error
- func (bt *SimpleTx) Delete(key ds.Key) error
- func (bt *SimpleTx) Discard()
- func (bt *SimpleTx) Get(k ds.Key) ([]byte, error)
- func (bt *SimpleTx) GetSize(k ds.Key) (int, error)
- func (bt *SimpleTx) Has(k ds.Key) (bool, error)
- func (bt *SimpleTx) Put(key ds.Key, val []byte) error
- func (bt *SimpleTx) Query(q query.Query) (query.Results, error)
- func (bt *SimpleTx) QueryExtended(q dse.QueryExt) (query.Results, error)
- type Sort
- type Txn
- 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) ModifiedSince(time int64) (ids []core.InstanceID, err error)
- func (t *Txn) RefreshCollection() error
- func (t *Txn) Save(updated ...[]byte) error
- func (t *Txn) Verify(updated ...[]byte) error
- type TxnMapDatastore
- type TxnOption
- type TxnOptions
- type Value
Constants ¶
Variables ¶
var ( // ErrInvalidCollectionSchemaPath indicates path does not resolve to a schema type. ErrInvalidCollectionSchemaPath = errors.New("collection schema does not contain path") // ErrCollectionNotFound indicates that the specified collection doesn't exist in the db. ErrCollectionNotFound = errors.New("collection not found") // ErrCollectionAlreadyRegistered indicates a collection with the given name is already registered. ErrCollectionAlreadyRegistered = errors.New("collection already registered") // ErrInstanceNotFound indicates that the specified instance doesn't exist in the collection. ErrInstanceNotFound = 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 collection schema. ErrInvalidSchemaInstance = errors.New("instance doesn't correspond to schema") )
var ( // ErrThreadReadKeyRequired indicates the provided thread key does not contain a read key. ErrThreadReadKeyRequired = errors.New("thread read key is required") // ErrInvalidName indicates the provided name isn't valid for a Collection. ErrInvalidName = errors.New("name may only contain alphanumeric characters or non-consecutive hyphens, " + "and cannot begin or end with a hyphen") // ErrInvalidCollectionSchema indicates the provided schema isn't valid for a Collection. ErrInvalidCollectionSchema = errors.New("the collection schema _id property must be a string") // ErrCannotIndexIDField indicates a custom index was specified on the ID field. ErrCannotIndexIDField = errors.New("cannot create custom index on " + idFieldName) )
var ( // ErrUniqueExists indicates an insert resulted in a unique constraint violation. ErrUniqueExists = errors.New("unique constraint violation") // ErrNotIndexable indicates an index path does not resolve to a value. ErrNotIndexable = errors.New("value not indexable") // ErrCantCreateUniqueIndex indicates a unique index can't be created because multiple instances share a value at path. ErrCantCreateUniqueIndex = errors.New("can't create unique index (duplicate instances exist)") // ErrIndexNotFound indicates a requested index was not found. ErrIndexNotFound = errors.New("index not found") )
var ( // ErrDBNotFound indicates that the specified db doesn't exist in the manager. ErrDBNotFound = errors.New("db not found") // ErrDBExists indicates that the specified db alrady exists in the manager. ErrDBExists = errors.New("db already exists") // MaxLoadConcurrency is the max number of dbs that will be concurrently loaded when the manager starts. MaxLoadConcurrency = 100 )
var ( // ErrInvalidSortingField is returned when a query sorts a result by a // non-existent field in the collection schema. ErrInvalidSortingField = errors.New("sorting field doesn't correspond to instance type") )
Functions ¶
func DefaultDecode ¶
DefaultDecode is the default decoding func from badgerhold (Gob).
func DefaultEncode ¶
DefaultEncode is the default encoding func from badgerhold (Gob).
Types ¶
type Action ¶
type Action struct { Collection string Type ActionType ID core.InstanceID }
type ActionType ¶
type ActionType int
const ( ActionCreate ActionType = iota + 1 ActionSave ActionDelete )
type Collection ¶
Collection is a group of instances sharing a schema. Collections are like RDBMS tables. They can only exist in a single database.
func (*Collection) Create ¶
func (c *Collection) Create(v []byte, opts ...TxnOption) (id core.InstanceID, err error)
Create creates an instance in the collection.
func (*Collection) CreateMany ¶ added in v0.1.13
func (c *Collection) CreateMany(vs [][]byte, opts ...TxnOption) (ids []core.InstanceID, err error)
CreateMany creates multiple instances in the collection.
func (*Collection) Delete ¶
func (c *Collection) Delete(id core.InstanceID, opts ...TxnOption) error
Delete deletes an instance by its ID. It doesn't fail if the ID doesn't exist.
func (*Collection) DeleteMany ¶ added in v0.1.13
func (c *Collection) DeleteMany(ids []core.InstanceID, opts ...TxnOption) error
DeleteMany deletes multiple instances by ID. It doesn't fail if one of the IDs don't exist.
func (*Collection) Find ¶
func (c *Collection) Find(q *Query, opts ...TxnOption) (instances [][]byte, err error)
Find executes a Query and returns the result.
func (*Collection) FindByID ¶
func (c *Collection) FindByID(id core.InstanceID, opts ...TxnOption) (instance []byte, err error)
FindByID finds an instance by its ID. If doesn't exists returns ErrInstanceNotFound.
func (*Collection) GetIndexes ¶ added in v0.1.19
func (c *Collection) GetIndexes() []Index
GetIndexes returns the current indexes.
func (*Collection) GetName ¶ added in v0.1.22
func (c *Collection) GetName() string
GetName returns the collection name.
func (*Collection) GetReadFilter ¶ added in v1.0.0
func (c *Collection) GetReadFilter() []byte
GetReadFilter returns the current collection read filter.
func (*Collection) GetSchema ¶ added in v0.1.22
func (c *Collection) GetSchema() []byte
GetSchema returns the current collection schema.
func (*Collection) GetWriteValidator ¶ added in v1.0.0
func (c *Collection) GetWriteValidator() []byte
GetWriteValidator returns the current collection write validator.
func (*Collection) Has ¶
func (c *Collection) Has(id core.InstanceID, opts ...TxnOption) (exists bool, err error)
Has returns true if ID exists in the collection, false otherwise.
func (*Collection) HasMany ¶ added in v0.1.13
func (c *Collection) HasMany(ids []core.InstanceID, opts ...TxnOption) (exists bool, err error)
HasMany returns true if all IDs exist in the collection, false otherwise.
func (*Collection) ModifiedSince ¶ added in v1.0.1
func (c *Collection) ModifiedSince(time int64, opts ...TxnOption) (ids []core.InstanceID, err error)
ModifiedSince returns a list of all instances that have been modified (and/or touched) since `time`.
func (*Collection) ReadTxn ¶
func (c *Collection) ReadTxn(f func(txn *Txn) error, opts ...TxnOption) error
ReadTxn creates an explicit readonly transaction. Any operation that tries to mutate an instance of the collection will ErrReadonlyTx. Provides serializable isolation gurantees.
func (*Collection) Save ¶
func (c *Collection) Save(v []byte, opts ...TxnOption) error
Save saves changes of an instance in the collection.
func (*Collection) SaveMany ¶ added in v0.1.13
func (c *Collection) SaveMany(vs [][]byte, opts ...TxnOption) error
SaveMany saves changes of multiple instances in the collection.
func (*Collection) Verify ¶ added in v1.0.0
func (c *Collection) Verify(v []byte, opts ...TxnOption) error
Verify verifies changes of an instance in the collection.
func (*Collection) VerifyMany ¶ added in v1.0.0
func (c *Collection) VerifyMany(vs [][]byte, opts ...TxnOption) error
VerifyMany verifies changes of multiple instances in the collection.
type CollectionConfig ¶
type CollectionConfig struct { // Name is the name of the collection. // Must only contain alphanumeric characters or non-consecutive hyphens, and cannot begin or end with a hyphen. Name string // Schema is JSON Schema used for instance validation. Schema *jsonschema.Schema // Indexes is a list of index configurations, which define how instances are indexed. Indexes []Index // An optional JavaScript (ECMAScript 5.1) function that is used to validate instances on write. // The function receives three arguments: // - writer: The multibase-encoded public key identity of the writer. // - event: An object describing the update event (see core.Event). // - instance: The current instance as a JavaScript object before the update event is applied. // A "falsy" return value indicates a failed validation (https://developer.mozilla.org/en-US/docs/Glossary/Falsy). // Note: Only the function body should be defined here. WriteValidator string // An optional JavaScript (ECMAScript 5.1) function that is used to filter instances on read. // The function receives two arguments: // - reader: The multibase-encoded public key identity of the reader. // - instance: The current instance as a JavaScript object. // The function must return a JavaScript object. // Most implementation will modify and return the current instance. // Note: Only the function body should be defined here. ReadFilter string }
CollectionConfig describes a new Collection.
type Comparer ¶
Comparer compares a type against the encoded value in the db. 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 Criterion ¶
type Criterion struct { FieldPath string Operation Operation Value Value // contains filtered or unexported fields }
Criterion represents a restriction on a field.
type DB ¶
DB is the aggregate-root of events and state. External/remote events are dispatched to the DB, and are internally processed to impact collection states. Likewise, local changes in collections registered produce events dispatched externally.
func NewDB ¶
func NewDB( ctx context.Context, store kt.TxnDatastoreExtended, network app.Net, id thread.ID, opts ...NewOption, ) (*DB, error)
NewDB creates a new DB, which will *own* ds and dispatcher for internal use. Saying it differently, ds and dispatcher shouldn't be used externally.
func NewDBFromAddr ¶
func NewDBFromAddr( ctx context.Context, store kt.TxnDatastoreExtended, network app.Net, addr ma.Multiaddr, key thread.Key, opts ...NewOption, ) (*DB, error)
NewDBFromAddr creates a new DB from a thread hosted by another peer at address, which will *own* ds and dispatcher for internal use. Saying it differently, ds and dispatcher shouldn't be used externally.
func (*DB) DeleteCollection ¶ added in v0.1.19
DeleteCollection deletes collection by name and drops all indexes.
func (*DB) GetCollection ¶
func (d *DB) GetCollection(name string, opts ...Option) *Collection
GetCollection returns a collection by name.
func (*DB) GetDBInfo ¶ added in v0.1.13
GetDBInfo returns the addresses and key that can be used to join the DB thread.
func (*DB) HandleNetRecord ¶ added in v0.1.13
func (*DB) ListCollections ¶ added in v0.1.22
func (d *DB) ListCollections(opts ...Option) []*Collection
ListCollections returns all collections.
func (*DB) Listen ¶
func (d *DB) Listen(los ...ListenOption) (Listener, error)
Listen returns a Listener which notifies about actions applying the defined filters. The DB *won't* wait for slow receivers, so if the channel is full, the action will be dropped.
func (*DB) NewCollection ¶
func (d *DB) NewCollection(config CollectionConfig, opts ...Option) (*Collection, error)
NewCollection creates a new db collection with config.
func (*DB) UpdateCollection ¶ added in v0.1.19
func (d *DB) UpdateCollection(config CollectionConfig, opts ...Option) (*Collection, error)
UpdateCollection updates an existing db collection with a new config. Indexes to new paths will be created. Indexes to removed paths will be dropped.
type DecodeFunc ¶
DecodeFunc is a function for decoding a value from bytes.
type EncodeFunc ¶
EncodeFunc is a function for encoding a value into bytes.
type Index ¶
type Index struct { // Path to the field to index in dot syntax, e.g., "name.last" or "age". Path string `json:"path"` // Unique indicates that only one instance should exist per field value. Unique bool `json:"unique,omitempty"` }
Index defines an index.
type ListenActionType ¶
type ListenActionType int
const ( ListenAll ListenActionType = iota ListenCreate ListenSave ListenDelete )
type ListenOption ¶
type ListenOption struct { Type ListenActionType Collection string ID core.InstanceID }
type ManagedOption ¶ added in v0.1.19
type ManagedOption func(*ManagedOptions)
ManagedOption specifies a managed db option.
func WithManagedToken ¶ added in v0.1.19
func WithManagedToken(t thread.Token) ManagedOption
WithManagedToken provides authorization for interacting with a managed db.
type ManagedOptions ¶ added in v0.1.19
ManagedOptions defines options for interacting with a managed db.
type Manager ¶
func NewManager ¶
func NewManager(store kt.TxnDatastoreExtended, network app.Net, opts ...NewOption) (*Manager, error)
NewManager hydrates and starts dbs from prefixes.
func (*Manager) NewDBFromAddr ¶
func (m *Manager) NewDBFromAddr( ctx context.Context, addr ma.Multiaddr, key thread.Key, opts ...NewManagedOption, ) (*DB, error)
NewDBFromAddr creates a new db from address and prefixes its datastore with base key. Unlike NewDB, this method takes a list of collections added to the original db that should also be added to this host.
type MarshaledResult ¶
type NewManagedOption ¶ added in v0.1.19
type NewManagedOption func(*NewManagedOptions)
NewManagedOption specifies a new managed db option.
func WithNewManagedBackfillBlock ¶ added in v0.1.22
func WithNewManagedBackfillBlock(block bool) NewManagedOption
WithNewBackfillBlock makes the caller of NewDBFromAddr block until the underlying thread is completely backfilled. Without this, NewDBFromAddr returns immediately and thread backfilling happens in the background.
func WithNewManagedCollections ¶ added in v0.1.19
func WithNewManagedCollections(cs ...CollectionConfig) NewManagedOption
WithNewManagedCollections is used to specify collections that will be created in a managed db.
func WithNewManagedKey ¶ added in v1.0.2
func WithNewManagedKey(key thread.Key) NewManagedOption
WithNewManagedKey provides control over thread keys to use with a managed db.
func WithNewManagedLogKey ¶ added in v1.0.0
func WithNewManagedLogKey(key crypto.Key) NewManagedOption
WithNewManagedLogKey is the public or private key used to write log records. If this is just a public key, the service itself won't be able to create records. In other words, all records must be pre-created and added with AddRecord. If no log key is provided, one will be created internally.
func WithNewManagedName ¶ added in v0.1.19
func WithNewManagedName(name string) NewManagedOption
WithNewManagedName assigns a name to a new managed db.
func WithNewManagedToken ¶ added in v0.1.19
func WithNewManagedToken(t thread.Token) NewManagedOption
WithNewManagedToken provides authorization for creating a new managed db.
type NewManagedOptions ¶ added in v0.1.19
type NewManagedOptions struct { Name string Key thread.Key LogKey crypto.Key Token thread.Token Collections []CollectionConfig Block bool }
NewManagedOptions defines options for creating a new managed db.
type NewOption ¶ added in v0.1.19
type NewOption func(*NewOptions)
NewOption specifies a new db option.
func WithNewBackfillBlock ¶ added in v0.1.22
WithNewBackfillBlock makes the caller of NewDBFromAddr block until the underlying thread is completely backfilled. Without this, NewDBFromAddr returns immediately and thread backfilling happens in the background.
func WithNewCollections ¶ added in v0.1.19
func WithNewCollections(cs ...CollectionConfig) NewOption
WithNewCollections is used to specify collections that will be created.
func WithNewDebug ¶ added in v0.1.19
WithNewDebug indicate to output debug information.
func WithNewEventCodec ¶ added in v0.1.19
func WithNewEventCodec(ec core.EventCodec) NewOption
WithNewEventCodec configure to use ec as the EventCodec for transforming actions in events, and viceversa.
func WithNewKey ¶ added in v1.0.2
WithNewKey provides control over thread keys to use with a db.
func WithNewLogKey ¶ added in v1.0.0
WithNewLogKey is the public or private key used to write log records. If this is just a public key, the service itself won't be able to create records. In other words, all records must be pre-created and added with AddRecord. If no log key is provided, one will be created internally.
func WithNewName ¶ added in v0.1.19
WithNewName sets the db name.
func WithNewToken ¶ added in v0.1.19
WithNewToken provides authorization for interacting with a db.
type NewOptions ¶ added in v0.1.19
type NewOptions struct { Name string Key thread.Key LogKey crypto.Key Collections []CollectionConfig Block bool EventCodec core.EventCodec Token thread.Token Debug bool }
NewOptions defines options for creating a new db.
type Query ¶
type Query struct { Ands []*Criterion Ors []*Query Sort Sort Seek core.InstanceID Limit int Skip int Index string }
Query is a json-seriable query representation.
func OrderByDesc ¶
OrderByDesc specifies descending order for the query results.
func OrderByID ¶ added in v1.0.0
func OrderByID() *Query
OrderByID specifies ascending ID order for the query results.
func OrderByIDDesc ¶ added in v1.0.0
func OrderByIDDesc() *Query
OrderByIDDesc specifies descending ID order for the query results.
func (*Query) Or ¶
Or 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 (*Query) OrderBy ¶
OrderBy specifies ascending order for the query results. On multiple calls, only the last one is considered.
func (*Query) OrderByDesc ¶
OrderByDesc specifies descending order for the query results. On multiple calls, only the last one is considered.
func (*Query) OrderByID ¶ added in v1.0.0
OrderByID specifies ascending ID order for the query results. On multiple calls, only the last one is considered.
func (*Query) OrderByIDDesc ¶ added in v1.0.0
OrderByIDDesc specifies descending ID order for the query results. On multiple calls, only the last one is considered.
func (*Query) SeekID ¶ added in v1.0.0
func (q *Query) SeekID(id core.InstanceID) *Query
SeekID seeks to the given ID before returning query results.
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 Txn ¶
type Txn struct {
// contains filtered or unexported fields
}
Txn represents a read/write transaction in the db. It allows for serializable isolation level within the db.
func (*Txn) Commit ¶
Commit applies all changes done in the current transaction to the collection. This is a syncrhonous call so changes can be assumed to be applied on function return.
func (*Txn) Create ¶
func (t *Txn) Create(new ...[]byte) ([]core.InstanceID, error)
Create creates new instances in the collection If the ID value on the instance is nil or otherwise a null value (e.g., ""), and ID is generated and used to store the instance.
func (*Txn) Delete ¶
func (t *Txn) Delete(ids ...core.InstanceID) error
Delete deletes instances by ID when the current transaction commits.
func (*Txn) Discard ¶
func (t *Txn) Discard()
Discard discards all changes done in the current transaction.
func (*Txn) FindByID ¶
func (t *Txn) FindByID(id core.InstanceID) ([]byte, error)
FindByID gets an instance by ID in the current txn scope.
func (*Txn) Has ¶
func (t *Txn) Has(ids ...core.InstanceID) (bool, error)
Has returns true if all IDs exists in the collection, false otherwise.
func (*Txn) ModifiedSince ¶ added in v1.1.0
func (t *Txn) ModifiedSince(time int64) (ids []core.InstanceID, err error)
ModifiedSince returns a list of all instances that have been modified (and/or touched) since `time`. The _mod field tracks modified instances, but not those that have been deleted, so we need to query the dispatcher for all (unique) instances in this collection that have been modified at all since `time`.
func (*Txn) RefreshCollection ¶ added in v1.0.0
RefreshCollection updates the transaction's collection reference from the master db map, which may have received updates while the transaction is open.
type TxnMapDatastore ¶ added in v1.1.0
type TxnMapDatastore struct { *ds.MapDatastore // contains filtered or unexported fields }
func NewTxMapDatastore ¶
func NewTxMapDatastore() *TxnMapDatastore
func (*TxnMapDatastore) NewTransaction ¶ added in v1.1.0
func (d *TxnMapDatastore) NewTransaction(_ bool) (ds.Txn, error)
func (*TxnMapDatastore) NewTransactionExtended ¶ added in v1.1.0
func (d *TxnMapDatastore) NewTransactionExtended(_ bool) (dse.TxnExt, error)
func (*TxnMapDatastore) QueryExtended ¶ added in v1.1.0
type TxnOption ¶ added in v0.1.13
type TxnOption func(*TxnOptions)
TxnOption specifies a transaction option.
func WithTxnToken ¶ added in v0.1.13
WithTxnToken provides authorization for the transaction.
type TxnOptions ¶ added in v0.1.13
TxnOptions defines options for a transaction.