0.1.1 • Published 3 years ago

kvutil v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

kvutil

a tiny utility to quickly use any database as a key-value storage and access using the same interface. to switch your database provider, simply swap the access url. no code changes are required.

supported methods:

  • get - get value
  • set - set value
  • delete - delete key
  • getOriginalClient - returns an initiated client with official SDK of the particular service
  • find - not implemented

supported databases

  • redis
  • mongo
  • firebase

installation

make sure you have node installed

node -v

install kvutil from npm

npm i kvutil

or

yarn add kvutil

usage

// import
const kvutil = require("kvutil");

initialize

using redis

const uri = "redis://default:********@containers-us-west-26.railway.app:6513";
const db = new kvutil("redis", url);

using mongo

const uri = "mongodb+srv://<user>:<pass>@<cluster>?writeConcern=majority";
const db = new kvutil("mongo", url);

operations

async function main() {
  // connect to database
  await db.connect();

  // write
  await db.set("foo", "bar");

  // read
  await db.get("foo");

  // delete
  await db.delete("foo");
  
  // disconnect
  await db.disconnect();

  // use official SDK of the service
  db.getOriginalClient();
}

feel free to open PRs and add more db services.

0.1.1

3 years ago

0.1.0

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago