0.1.1 • Published 3 years ago
kvutil v0.1.1
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 valueset
- set valuedelete
- delete keygetOriginalClient
- returns an initiated client with official SDK of the particular servicefind
- 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.