Table of Contents
- Backed Implementations
- Wrapper Implementations
If you want the same functionality as go-ds-flatfs, use sharding with fs.
const FsStore =const ShardingStore = ShardingDatatstoreconst NextToLast = shardNextToLastconst fs = 'path/to/store'// flatfs now works like go-flatfsconst flatfs = await ShardingStore
$ npm install interface-datastore
The type definitions for this package are available on http://definitelytyped.org/. To install just use:
$ npm install -D @types/interface-datastore
const MemoryStore = MemoryDatastoreconst MountStore = MountDatastoreconst Key = Keyconst store = prefix: '/a' datastore:
To allow a better abstraction on how to address values, there is a
Key class which is used as identifier. It's easy to create a key from a
Buffer or a
const a = 'a'const b = 'hello'
The key scheme is inspired by file systems and Google App Engine key model. Keys are meant to be unique across a system. They are typically hierarchical, incorporating more and more specific namespaces. Thus keys can be deemed 'children' or 'ancestors' of other keys:
Also, every namespace can be parameterized to embed relevant object information. For example, the Key
name (most specific namespace) could include the object type:
The exact types can be found in
These methods will be present on every datastore.
Key always means an instance of the above mentioned Key type. Every datastore is generic over the
Value type, though currently all backing implementations are implemented only for
Check for the existence of a given key
const exists = await storeconsole
put(key, value) ->
Store a value with the given key.
Retrieve the value stored under the given key.
const value = await storeconsole// => got content: datastore
Delete the content stored under the given key.
query: Querysee below for possible values
Search the store for some values. Returns an Iterable with each item being a
// retrieve __all__ values from the storelet list =for await const value of storelistconsole
Object in the form with the following optional properties
prefix: string(optional) - only return values where the key starts with this prefix
filters: Array<Filter<Value>>(optional) - filter the results according to the these functions
orders: Array<Order<Value>>(optional) - order the results according to these functions
limit: Number(optional) - only return this many records
offset: Number(optional) - skip this many records at the beginning
keysOnly: Boolean(optional) - Only return keys, no values.
This will return an object with which you can chain multiple operations together, with them only being executed on calling
const b = storefor let i = 0; i < 100; i++bawait bconsole
Queue a put operation to the store.
Queue a delete operation to the store.
Write all queued operations to the underyling store. The batch object should not be used after calling this.
Opens the datastore, this is only needed if the store was closed before, otherwise this is taken care of by the constructor.
Close the datastore, this should always be called to ensure resources are cleaned up.
Small note: If editing the Readme, please conform to the standard-readme specification.
MIT 2017 © IPFS