flash-store
Version:
FlashStore is a Key-Value persistent storage with easy to use ES6 Map-like API(both Async and Sync support), powered by LevelDB and TypeScript.
129 lines (128 loc) • 3.99 kB
TypeScript
import { AsyncMapLike } from 'async-map-like';
export interface IteratorOptions {
gt?: any;
gte?: any;
lt?: any;
lte?: any;
reverse?: boolean;
limit?: number;
prefix?: any;
}
export declare class FlashStore<K = any, V = any> implements AsyncMapLike<K, V> {
workdir: string;
static VERSION: string;
private levelDb;
/**
* FlashStore is a Key-Value database tool and makes using leveldb more easy for Node.js
*
* Creates an instance of FlashStore.
* @param {string} [workdir=path.join(appRoot, 'flash-store.workdir')]
* @example
* import { FlashStore } from 'flash-store'
* const flashStore = new FlashStore('flashstore.workdir')
*/
constructor(workdir?: string);
version(): string;
/**
* Put data in database
*
* @param {K} key
* @param {V} value
* @returns {Promise<void>}
* @example
* await flashStore.put(1, 1)
*/
put(key: K, value: V): Promise<void>;
set(key: K, value: V): Promise<AsyncMapLike<K, V>>;
/**
* Get value from database by key
*
* @param {K} key
* @returns {(Promise<V | null>)}
* @example
* console.log(await flashStore.get(1))
*/
get(key: K): Promise<V | undefined>;
/**
* Del data by key
*
* @param {K} key
* @returns {Promise<void>}
* @example
* await flashStore.del(1)
*/
del(key: K): Promise<void>;
delete(key: K): Promise<boolean>;
/**
* @typedef IteratorOptions
*
* @property { any } gt - Matches values that are greater than a specified value
* @property { any } gte - Matches values that are greater than or equal to a specified value.
* @property { any } lt - Matches values that are less than a specified value.
* @property { any } lte - Matches values that are less than or equal to a specified value.
* @property { boolean } reverse - Reverse the result set
* @property { number } limit - Limits the number in the result set.
* @property { any } prefix - Make the same prefix key get together.
*/
/**
* Find keys by IteratorOptions
*
* @param {IteratorOptions} [options={}]
* @returns {AsyncIterableIterator<K>}
* @example
* const flashStore = new FlashStore('flashstore.workdir')
* for await(const key of flashStore.keys({gte: 1})) {
* console.log(key)
* }
*/
keys(options?: IteratorOptions): AsyncIterableIterator<K>;
/**
* Find all values
*
* @returns {AsyncIterableIterator<V>}
* @example
* const flashStore = new FlashStore('flashstore.workdir')
* for await(const value of flashStore.values()) {
* console.log(value)
* }
*/
values(options?: IteratorOptions): AsyncIterableIterator<V>;
/**
* Get the counts of the database
* @deprecated use property `size` instead
* @returns {Promise<number>}
* @example
* const count = await flashStore.count()
* console.log(`database count: ${count}`)
*/
count(): Promise<number>;
get size(): Promise<number>;
/**
* FIXME: use better way to do this
*/
has(key: K): Promise<boolean>;
/**
* TODO: use better way to do this with leveldb
*/
clear(): Promise<void>;
get [Symbol.toStringTag](): Promise<string>;
[Symbol.iterator](): AsyncIterableIterator<[K, V]>;
/**
* @private
*/
entries(options?: IteratorOptions): AsyncIterableIterator<[K, V]>;
[Symbol.asyncIterator](): AsyncIterableIterator<[K, V]>;
/**
* @private
*/
streamAsyncIterator(): AsyncIterator<[K, V]>;
forEach(callbackfn: (value: V, key: K, map: any) => void, thisArg?: any): Promise<void>;
close(): Promise<void>;
/**
* Destroy the database
*
* @returns {Promise<void>}
*/
destroy(): Promise<void>;
}
export default FlashStore;