kv-storage
Create data storage that uses a simple key-value method for Node, Browser, Deno, Bun, Cloudflare Workers
![npm version](https://badge.fury.io/js/kv-storage.svg)
Features
- ✅ 0 Dependencies
- ✅ NoSQL Database
- ✅ Lightwight
Demo
https://codesandbox.io/p/devbox/simple-kv-storage-pzr9ld
Installation
npm install kv-storage
Initialization
const {KVStorage} = require('kv-storage')
import {KVStorage} from 'kv-storage'
import {KVStorage} from 'npm:kv-storage'
const db = await KVStorage({
runtime:'node',
storageName:'storage'
})
Example Usage
const {KVStorage} = require('kv-storage')
void async function main() {
const db = await KVStorage({
runtime:'node',
storageName:'storage'
})
console.log(await db.put('key','value'))
console.log(await db.get('key'))
console.log(await db.list())
console.log(await db.delete('key'))
console.log(await db.has('key'))
}()
import {KVStorage} from 'kv-storage'
void async function main() {
const db = await KVStorage({
runtime:'node',
storageName:'storage'
})
console.log(await db.put('key','value'))
console.log(await db.get('key'))
console.log(await db.list())
console.log(await db.delete('key'))
console.log(await db.has('key'))
}()
import {KVStorage} from 'npm:kv-storage'
void async function main() {
const db = await KVStorage({
runtime:'deno',
storageName:'storage'
})
console.log(await db.put('key','value'))
console.log(await db.get('key'))
console.log(await db.list())
console.log(await db.delete('key'))
console.log(await db.has('key'))
}()
<script type="module">
import {KVStorage} from 'https://cdn.jsdelivr.net/npm/kv-storage@0.0.3/dist/mjs/kv-storage.js'
void async function main() {
const db = await KVStorage({
runtime:'browser',
storageName:'storage'
})
console.log(await db.put('key','value'))
console.log(await db.get('key'))
console.log(await db.list())
console.log(await db.delete('key'))
console.log(await db.has('key'))
}()
</script>
API Reference
Documentation
https://nuzulul.github.io/kv-storage/
Init Parameters
await init({
runtime?:string,
storageName?:string
})
runtime = Javascript runtime
storageName = Alphanumeric name of storage
Supported runtime :
Write key-value pairs
await put(key:string,value:string)
The put() method returns a Promise that you should await on to verify a successful update, resolve to true
or false
Read key-value pairs
await get(key:string)
The get() method returns a promise you can await on to get the value, resolve to the value or false
List keys
await list()
Use a list operation to view all the keys that live in a given storage, return a promise which resolves with an object consist of:
- keys = Array of keys
- complete = True if operation complete
Delete key-value pairs
await delete(key:string)
To delete a key-value pair, call the delete() method, resolve to true
or false
Has key-value pairs
await has(key:string)
To check for the existence of a key, resolve to true
or false
License
MIT