DEV Community

Oluwaseyi Muyiwa
Oluwaseyi Muyiwa

Posted on

VanillaDB: A Tiny Browser-Based Database

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
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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)

Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

where key is the key of the data stored in Database


const db =  'local' // 'session',
const key = 'your database key',

vanillaDb.remove(db, key)

Enter fullscreen mode Exit fullscreen mode

db is the Database you stored data in and the database key.


const db =  'local' // 'session',

vanillaDb.length(db)

Enter fullscreen mode Exit fullscreen mode

db is the Database you stored data.

NPM JavaScript Style Guide

Top comments (2)

Collapse
 
robsongrangeiro profile image
Robson Grangeiro • Edited

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!

Collapse
 
zedic profile image
Oluwaseyi Muyiwa

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