kvstoreds

package module
v1.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: Apache-2.0, MIT Imports: 9 Imported by: 2

README

go-ds-kvstore: KVStore-backed datastore

go-ds-kvstore implements the go-datastore interface using a iotaledger/hive.go/kvstore backend.

Status

This implementation is experimental. It is currently exercised against the test suite under go-datastore.

License

Dual-licensed under MIT + Apache 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batch

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

func (*Batch) Commit

func (b *Batch) Commit(ctx context.Context) error

Commit finalizes a transaction, attempting to commit it to the Datastore. May return an error if the transaction has gone stale. The presence of an error is an indication that the data was not committed to the Datastore.

func (*Batch) Delete

func (b *Batch) Delete(ctx context.Context, key ds.Key) error

Delete removes the value for given `key`. If the key is not in the datastore, this method returns no error.

func (*Batch) Put

func (b *Batch) Put(ctx context.Context, key ds.Key, value []byte) error

Put stores the object `value` named by `key`.

The generalized Datastore interface does not impose a value type, allowing various datastore middleware implementations (which do not handle the values directly) to be composed together.

Ultimately, the lowest-level datastore will need to do some value checking or risk getting incorrect values. It may also be useful to expose a more type-safe interface to your application, and do the checking up-front.

type Datastore

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

Datastore is a github.com/iotaledger/hive.go/core/kvstore backed github.com/ipfs/go-datastore.

func NewDatastore

func NewDatastore(store kvstore.KVStore) *Datastore

NewDatastore creates a kvstore-backed datastore.

func (*Datastore) Batch

func (d *Datastore) Batch(ctx context.Context) (ds.Batch, error)

func (*Datastore) Close

func (d *Datastore) Close() error

func (*Datastore) Delete

func (d *Datastore) Delete(ctx context.Context, key ds.Key) error

Delete removes the value for given `key`. If the key is not in the datastore, this method returns no error.

func (*Datastore) Get

func (d *Datastore) Get(ctx context.Context, key ds.Key) ([]byte, error)

Get retrieves the object `value` named by `key`. Get will return ErrNotFound if the key is not mapped to a value.

func (*Datastore) GetSize

func (d *Datastore) GetSize(ctx context.Context, key ds.Key) (int, error)

GetSize returns the size of the `value` named by `key`. In some contexts, it may be much cheaper to only get the size of the value rather than retrieving the value itself.

func (*Datastore) Has

func (d *Datastore) Has(ctx context.Context, key ds.Key) (bool, error)

Has returns whether the `key` is mapped to a `value`. In some contexts, it may be much cheaper only to check for existence of a value, rather than retrieving the value itself.

func (*Datastore) Put

func (d *Datastore) Put(ctx context.Context, key ds.Key, value []byte) error

Put stores the object `value` named by `key`.

The generalized Datastore interface does not impose a value type, allowing various datastore middleware implementations (which do not handle the values directly) to be composed together.

Ultimately, the lowest-level datastore will need to do some value checking or risk getting incorrect values. It may also be useful to expose a more type-safe interface to your application, and do the checking up-front.

func (*Datastore) Query

func (d *Datastore) Query(ctx context.Context, q query.Query) (query.Results, error)

Query searches the datastore and returns a query result. This function may return before the query actually runs. To wait for the query:

result, _ := ds.Query(q)

// use the channel interface; result may come in at different times
for entry := range result.Next() { ... }

// or wait for the query to be completely done
entries, _ := result.Rest()
for entry := range entries { ... }

func (*Datastore) Sync

func (d *Datastore) Sync(ctx context.Context, _ ds.Key) error

Sync guarantees that any Put or Delete calls under prefix that returned before Sync(prefix) was called will be observed after Sync(prefix) returns, even if the program crashes. If Put/Delete operations already satisfy these requirements then Sync may be a no-op.

If the prefix fails to Sync this method returns an error.

Jump to

Keyboard shortcuts

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