nod

nodbstore

Simple database using memory and can be extended by multiple storages

Showing:

Popularity

Downloads/wk

14

GitHub Stars

0

Maintenance

Last Commit

3yrs ago

Contributors

0

Package

Dependencies

0

Size (min+gzip)

0.9KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

NoDBStore

Simple database working on memory and can have multiple storage

it will be use for small data that need to be stored easily with a simple api

Getting started

npm i nodbstore

create the db

Only in memory

const nodbstore = require('nodbstore')
// create a database (a simple table)
const db = new nodbstore()

insert an element

// O(1)
const entry = db.put({ some: 'data', and: ['more', 'if', 'you', 'want'] })

edit an element

// O(1)
const editedEntry = db.put({ _id: entry._id, add: 'a field', some: undefined })

remove an element

// O(1)
const deletedEntry = db.remove(entry._id)

get an entry

// O(1)
const gettedEntry = db.get(entry._id)

find an element

// O(n)
// stop when it finded one
const entry = db.findOne(entry => entry.some === 'data')

// start from the end
const entry = db.findOne(entry => entry.some === 'data', true)

// return null if it doesnt find something

find all entries

// O(n)
// always return an array
const entries = db.find(entry => entry.some === 'data')

export

// to JSON string
db.toJson()
// to JS Object !! thats not a clone !
db.toObj()

// if you want a clone :
JSON.parse(db.toJson())

import

// from JSON string
db.loadJson(jsonString)
// from exported db object !! it will edit directly the object
db.loadObj(exportedDbObject)

// wana work from a clone
db.loadJson(JSON.stringify(exportedDbObject))

add a storage

class NewStore extends nodbstore.Storage {
  write(json) { // trigger when some data are updated
    // you can add test if you want to skip write in some case
    if (console.log === undefined) return
    this.nodb // the instance of the database
    console.log(json)
    json === this.nodb.toJson() // -> true
  }
  // can be omited
  load() { // called manuall or with nodb.loadFromStore( store )
    this.nodb.loadJson(/* json of db obtained with love */)
  }
  // can be omited
  init() { // trigger when store is added to nodb
    this.data.that.I.will.use.later = 'some'
    // or do WTFYW
  }

}

db.addStore(new NewStore())

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100