Socket
Socket
Sign inDemoInstall

@qgisk/kv

Package Overview
Dependencies
223
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @qgisk/kv

Simple KV implementation for MongoDB


Version published
Weekly downloads
10
increased by900%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

0.0.9 (2021-12-29)

Other

  • add keywords (f2d2195)

Readme

Source

KV

NPM version NPM downloads

About

KV is a simple MongoDB based key value store.

If you're looking for a key value library that supports more than just MongoDB checkout keyv

If you're looking for a CLI checkout this

Installation

npm i @qgisk/kv mongoose

Example

Simple quick start example

import {KV} from '@qgisk/kv';
// or for commonjs
const {KV} = require('@qgisk/kv');

// First value is the mongodb uri, the second is your namespace.
// db uri defaults to mongodb://localhost:27017/kv
// namespace defaults to 'kv'
const kv = new KV('uri', 'namespace');

await kv.set('key', 'value');

await kv.get('key'); // value

Multiple namespaces

Using multiple namespaces so you dont get conflicts

const users = new KV(undefined, 'users');
const posts = new KV(undefined, 'posts');

await users.set('one', 'user');
await posts.set('one', 'post');

await users.get('one'); // user
await posts.get('one'); // post

All values in namespace

Easily get all values in a namespace

const users = new KV(undefined, 'users');

await users.set('one', 'user');
await users.set('two', 'user');

await users.all(); // [{key: 'users:one', value: 'user'}, {key: 'users:two', value: 'user'}]

Delete a key

Delete key in your current namespace

const users = new KV(undefined, 'users');

await users.del('one', 'user');

await users.get('one'); // undefined

Clear a namespace

Clear a whole namespace

const users = new KV(undefined, 'users');

await users.set('one', 'user');
await users.clear();

await users.get('one'); // undefined

Mongoose error events

const kv = new KV('mongodb://123/');

kv.on('error', e => console.log(e));

TTL

const kv = new KV(undefined, 'ttl');

await kv.set('test', 'hi', 5000); // 5 seconds
setTimeout(() => console.log(await kv.get('test')), 5000); // undefined

MIT Demian

Keywords

FAQs

Last updated on 29 Dec 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc