Skip to content

Simple nodejs key-value store with file persistence and optional async write queue.

License

Notifications You must be signed in to change notification settings

binaryrelay/flatkvp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

NOTES:

  • This is still alpha stage.
  • The Sync methods, if using the multiprocess flag, can hold up the thread for many seconds while trying to acquire a lock.

Store

Simple key-value store with file persistence and optional async write queue.

Kind: global class

new Store([options])

Initializes the store.

Param Type Description
[options] object Path to JSON file for storage.

store.get(key) *

Retrieves the value associated with the provided key.

Kind: instance method of Store
Returns: * - The value associated with the key, or undefined if the key doesn't exist.

Param Type Description
key string The key to search for.

store.set(key, value)

Asynchronously sets the value for a given key.

Kind: instance method of Store
Throws:

  • Error If the value is not a primitive type.
Param Type Description
key string The key to set.
value * The value to set. Must be a primitive type (string, number, or boolean).

store.setSync(key, value)

Synchronously sets the value for a given key.

Kind: instance method of Store
Throws:

  • Error If the value is not a primitive type.
Param Type Description
key string The key to set.
value * The value to set. Must be a primitive type (string, number, or boolean).

store.remove(key)

Asynchronously removes a key and its associated value from the store.

Kind: instance method of Store
Throws:

  • Error If the key doesn't exist in the store.
Param Type Description
key string The key to remove.

store.removeSync(key)

Synchronously removes a key and its associated value from the store.

Kind: instance method of Store
Throws:

  • Error If the key doesn't exist in the store.
Param Type Description
key string The key to remove.

store.clear()

Clears all key-value pairs from the store.

Kind: instance method of Store

store.changeFeed(listener)

Subscribes a listener function to changes in the store. The listener is called whenever a key's value changes.

Kind: instance method of Store

Param Type Description
listener function The function to call when a change occurs.

store.removeChangeFeedListener(listener) boolean

Unsubscribes a listener from the change feed.

Kind: instance method of Store
Returns: boolean - Returns true if the listener was found and removed, otherwise false.

Param Type Description
listener function The listener to unsubscribe.

store.getAll() Object

Retrieves all key-value pairs currently in the store.

Kind: instance method of Store
Returns: Object - An object containing all key-value pairs.

About

Simple nodejs key-value store with file persistence and optional async write queue.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published