react-native-levelstorage

Class: Storage<T>

Fast and simple key-value pair storage for React Native using LevelDB native binding.

Constructors

Accessors

Methods

Constructors

constructor

+ new Storage(name: string, buffer?: boolean): Storage

The level storage instance. Key must be string | number and value can either be string or buffer.

Default: string.

Parameters:

Name Type Default value Description
name string - The name of the storage
buffer boolean false Make values as buffer, instead of string

Returns: Storage

Accessors

length

• get length(): Promise<number>

Returns the number of items in the storage.

Returns: Promise<number>

Methods

clear

clear(): Promise<void>

Removes all items in storage.

Returns: Promise<void>


create

create(name: string): Storage<string>

Create new instance of storage with string type values.

Parameters:

Name Type Description
name string The name of storage

Returns: Storage<string>

create(name: string, buffer: true): Storage<Buffer>

Create new instance of storage with Buffer type values.

Parameters:

Name Type Description
name string The name of storage
buffer true Set true to make values as buffer

Returns: Storage<Buffer>


filter

filter(condition: (value: T, key: string) => boolean, options?: AbstractIteratorOptions<any>): Promise<T[]>

Iterates over items, returning new array of all items predicate returns truthy for.

Options:

Type T is either string or buffer.

Parameters:

Name Type Description
condition (value: T, key: string) => boolean The function to invoke per iteration
options? AbstractIteratorOptions<any> The options object

Returns: Promise<T[]>


forEach

forEach(iteratee: (value: T, key: string) => false | void, options?: AbstractIteratorOptions<any>): Promise<void>

Iterates over items.

Parameters:

Name Type Description
iteratee (value: T, key: string) => false | void The function to invoke per iteration
options? AbstractIteratorOptions<any> The same options with filter

Returns: Promise<void>


getItem

getItem(key: string | number): Promise<T | null>

Get the value. Either string or buffer depending on what you specified. Will convert key to string if not string.

Parameters:

Name Type Description
key string | number Name of the item

Returns: Promise<T | null>


keys

keys(): Promise<string[]>

Returns an array of all keys.

Returns: Promise<string[]>


removeItem

removeItem(key: string | number): Promise<void>

Remove the item in storage. Will convert key to string if not string.

Parameters:

Name Type Description
key string | number Name of the item

Returns: Promise<void>


setItem

setItem(key: string | number, value: T): Promise<void>

Store a value. Must be string or buffer depending on what you specified. Will convert key to string if not string.

Parameters:

Name Type Description
key string | number Name of the item
value T Value to store

Returns: Promise<void>


values

values(): Promise<T[]>

Returns an array of all values.

Returns: Promise<T[]>