FlashStore is Key-Value persistent storage with easy to use ES6 Map-like API(both Async and Sync support), powered by LevelDB and TypeScript.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
docs
example
scripts
src
tests/fixtures
.editorconfig
.gitignore
.travis.yml
LICENSE
README.md
appveyor.yml
index.ts
package.json
rollup.config.js
tsconfig.json
tslint.json

README.md

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.11 master 2018

  1. Use level-down as backend to skip the compiling when install.

v0.7 Aug 2018

  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> (http://linkedin.com/in/zixia)

profile for zixia at Stack Overflow, Q&A for professional and enthusiast programmers

COPYRIGHT & LICENSE

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