Documentation ¶
Overview ¶
Package keytransform introduces a Datastore Shim that transforms keys before passing them to its child. It can be used to manipulate what keys look like to the user, for example namespacing keys, reversing them, etc.
Use the Wrap function to wrap a datastore with any KeyTransform. A KeyTransform is simply an interface with two functions, a conversion and its inverse. For example:
import ( ktds "github.com/ipfs/go-datastore/keytransform" ds "github.com/ipfs/go-datastore" ) func reverseKey(k ds.Key) ds.Key { return k.Reverse() } func invertKeys(d ds.Datastore) { return ktds.Wrap(d, &ktds.Pair{ Convert: reverseKey, Invert: reverseKey, // reverse is its own inverse. }) }
Index ¶
- type Datastore
- func (d *Datastore) Batch() (ds.Batch, error)
- func (d *Datastore) Check() error
- func (d *Datastore) Children() []ds.Datastore
- func (d *Datastore) Close() error
- func (d *Datastore) CollectGarbage() error
- func (d *Datastore) Delete(key ds.Key) (err error)
- func (d *Datastore) DiskUsage() (uint64, error)
- func (d *Datastore) Get(key ds.Key) (value []byte, err error)
- func (d *Datastore) GetSize(key ds.Key) (size int, err error)
- func (d *Datastore) Has(key ds.Key) (exists bool, err error)
- func (d *Datastore) Put(key ds.Key, value []byte) (err error)
- func (d *Datastore) Query(q dsq.Query) (dsq.Results, error)
- func (d *Datastore) Scrub() error
- func (d *Datastore) Sync(prefix ds.Key) error
- type KeyMapping
- type KeyTransform
- type Pair
- type PrefixTransform
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Datastore ¶
type Datastore struct { KeyTransform // contains filtered or unexported fields }
Datastore keeps a KeyTransform function
func Wrap ¶
func Wrap(child ds.Datastore, t KeyTransform) *Datastore
Wrap wraps a given datastore with a KeyTransform function. The resulting wrapped datastore will use the transform on all Datastore operations.
func (*Datastore) CollectGarbage ¶ added in v0.0.5
func (*Datastore) DiskUsage ¶ added in v0.0.5
DiskUsage implements the PersistentDatastore interface.
func (*Datastore) Get ¶ added in v0.0.5
Get returns the value for given key, transforming the key first.
func (*Datastore) GetSize ¶ added in v0.0.5
GetSize returns the size of the value named by the given key, transforming the key first.
func (*Datastore) Has ¶ added in v0.0.5
Has returns whether the datastore has a value for a given key, transforming the key first.
type KeyMapping ¶
KeyMapping is a function that maps one key to annother
type KeyTransform ¶
KeyTransform is an object with a pair of functions for (invertibly) transforming keys
type Pair ¶
type Pair struct { Convert KeyMapping Invert KeyMapping }
Pair is a convince struct for constructing a key transform.
type PrefixTransform ¶ added in v0.0.5
PrefixTransform constructs a KeyTransform with a pair of functions that add or remove the given prefix key.
Warning: will panic if prefix not found when it should be there. This is to avoid insidious data inconsistency errors.
func (PrefixTransform) ConvertKey ¶ added in v0.0.5
func (p PrefixTransform) ConvertKey(k ds.Key) ds.Key
ConvertKey adds the prefix.