JSPM

  • Created
  • Published
  • Downloads 767
  • Score
    100M100P100Q99336F
  • License Apache-2.0

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.

Package Exports

  • flash-store

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (flash-store) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

FLASH-STORE

Powered by LevelDB Powered by TypeScript Build Status Build status NPM Version npm (tag) Downloads node Greenkeeper badge

FlashStore is Key-Value persistent storage with easy to use ES6 Map-like API(both Async and Sync support), powered by LevelDB and TypeScript.

flash store

REQUIRES

  1. Node.js v10 or above

EXAMPLES

Try the following command

npm install
npm run demo

The basic function as follows:

import { FlashStore } from 'flash-store'

const flashStore = new FlashStore('flashstore.workdir')

await flashStore.put(1, 'a')
console.log(`key: 1, value: ${await flashStore.get(1)}`)
// Output: 'a'

await flashStore.del(1)
console.log(`key: 1, value: ${await flashStore.get(1)}`)
// Output: undefined

API Reference

FlashStore

FlashStore implments the Standard ES6 Map API with Async modification:

/**
 * ES6 Map API with Async
 */
export interface AsyncMap<K = any, V = any> {
  [Symbol.asyncIterator]() : AsyncIterableIterator<[K, V]>
  size                     : Promise<number>

  clear   ()                 : Promise<void>
  delete  (key: K)           : Promise<void>
  entries()                  : AsyncIterableIterator<[K, V]>
  get     (key: K)           : Promise<V | undefined>
  has     (key: K)           : Promise<boolean>
  keys    ()                 : AsyncIterableIterator<K>
  set     (key: K, value: V) : Promise<void>
  values  ()                 : AsyncIterableIterator<V>
}

class FlashStore<K, V> implments AsyncMap<K, V> {}

FlashStoreSync

FlashStoreSync implments the Standard ES6 Map API:

class FlashStoreSync<K, V> implments Map<K, V> {}

DOCUMENT

See auto generated docs

SEE ALSO

  1. Node.js databases: an embedded database using LevelDB
  2. How to Cook a Graph Database in a Night - LevelGraph
  3. Graph database JS style for Node.js and the Browser. Built upon LevelUp and LevelDB.
  4. 浅析 Bigtable 和 LevelDB 的实现

CHANGELOG

v0.17 master 2019

v0.16 May 2019 SnapDB as Backend

  1. Switch from RocksDB to SnapDB #45

v0.14 May 2019 RocksDB as Backend

  1. Switch from LevelDB to RocksDB #34

v0.12 Jan 2019 LevelDB as Backend

  1. Use level-down as backend to skip the compiling when install.
  2. Using leveldb official typings from @types/

v0.7 Aug 2018 Nosql-LevelDB as Backend

  1. Use nosql-leveldb as backend to prevent segfault.

v0.6 Jul 2018

  1. Upgrade to TypeScript 3.0

v0.4 Jun 2018

1. Refactor API to implenment ES6 Map interface

  1. Update the API to ES6 Map-like, the difference is that FlashStore is all async.

2. Add FlashStoreSync as a in-memory Write-back Cache for Flash-Store

Add a new class FlashStoreSync which is a in-memory full loaded Write-back Cache for Flash-Store:

  1. Writes directly to cache, lazy writes to store.
  2. Reads from cache, never read-miss because cache have the full data of the store which will never expire.
  3. API of FlashStoreSync is the same as the ES6 Map

v0.2 Sep 2017

Init version, API is LevelDB-like.

FAQ

Q: What's the difference between the flash-store and memory-card?

Short answer:

  1. flash-store is for save data to local flesystem.
  2. memory-card is for save data to a distributed network storage, it can be serilized/deserilized safely by design.

Long answer:

flash-store and memory-card are all built by @huan, and they are all follow the ES6 Map API.

flash-store is using a no-sql local file database to maximum the performance, it can be used as a local database, or a local cache for whatever you want to catch from a network database.

memory-card is using a local file to store data in JSON format by default, however, it supports more distributed methods. Learn more from it's repository at here

AUTHOR

Huan LI (李卓桓) <zixia@zixia.net>

Profile of Huan LI (李卓桓) on StackOverflow

  • Code & Docs © 2017-2019 Huan LI <zixia@zixia.net>
  • Code released under the Apache-2.0 License
  • Docs released under Creative Commons