@lucasvmiguel/kv-store
TypeScript icon, indicating that this package has built-in type declarations

1.0.20 • Public • Published

kv-store

Version Build Status Downloads

Description

Key value store library that uses your current database. It might be the case that you don't want to spend money in a new instance or in another service.

PS: if you have money to spend, maybe it's better to use a better database solution for this particular problem, as suggested here: https://www.reddit.com/r/javascript/comments/beyjef/key_value_storage_in_your_own_database_if_you/el9s32b?utm_source=share&utm_medium=web2x

Databases available:

  • Mysql
  • Postgres (roadmap)
  • MongoDB (roadmap)

Installation

npm install --save @lucasvmiguel/kv-store

How to use

import * as kvStore from '@lucasvmiguel/kv-store';

const connection = mysql.createConnection({
    host: '...',
    user: '...',
    password: '...',
    port: '...',
    database: '...',
});

await kvStore.init({
  type: 'mysql',
  client: connection,
  tableName: 'kvstore_keyvalues', // OPTIONAL
  debug: false, // OPTIONAL
});

await kvStore.put('USER:123', 'abc');
const abc = await kvStore.get('USER:123');

// Expiration in seconds
await kvStore.putJson('USER:456', {foo: "bar"}, { expiration: 60 });
const fooBar = await kvStore.getJson('USER:456');

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @lucasvmiguel/kv-store

Weekly Downloads

2

Version

1.0.20

License

MIT

Unpacked Size

107 kB

Total Files

18

Last publish

Collaborators

  • lucasvmiguel