VanillaDB
VanillaDB is a tiny browser-based database library that is built on localstorage, sessionStorage and indexedDB.
Installation
Install vanilla-DB using npm
npm install --save vanilla-db
Usage/Examples
Once the package is installed, you can import the library using import
import { vanillaDb } from 'vanilla-db'
const config = {
db: 'local' // 'session',
key: 'your database key',
data
}
vanillaDb.set(config)
config contains your database of choice which can either be "local" or "session", your database key and the data you intended to store in the DB.
const query = {
db: 'local' // 'session',
key: 'your database key',
}
vanillaDb.get(query)
query contains the Database you stored data in and the database key.
More Features
- sync(key) - sync data stored in session to local Database
- remove(db, key) - remove stored data by key
- length(db) - return the length of data stored in Database
Usage/Examples
import { vanillaDb } from 'vanilla-db'
vanillaDb.sync(key)
where key is the key of the data stored in Database
const db = 'local' // 'session',
const key = 'your database key',
vanillaDb.remove(db, key)
db is the Database you stored data in and the database key.
const db = 'local' // 'session',
vanillaDb.length(db)
db is the Database you stored data.
Top comments (2)
This is quite interest! Which a use case to use this tool? Or perhaps, could you show a simple implementation of this in your next post? I thinking to use this with a large objects maybe...
Thank you!
Browser database can be used in any project ranging from small todo app to big app that needs to store some datas on the browser, I will show how to implement the tool in my next post