{"id":14460210,"url":"https://github.com/nuzulul/kv-storage","last_synced_at":"2025-05-01T10:31:35.512Z","repository":{"id":219914196,"uuid":"750136163","full_name":"nuzulul/kv-storage","owner":"nuzulul","description":"💾 Create data storage that uses a simple key-value method for Node, Browser, Deno, Bun, Cloudflare Workers","archived":false,"fork":false,"pushed_at":"2024-07-17T21:50:30.000Z","size":76,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T07:43:42.430Z","etag":null,"topics":["cloudflare-workers","data-storage","data-store","database","db","file","file-database","file-storage","indexeddb","kv-storage","node-js","nodejs","nosql","nosql-database","storage"],"latest_commit_sha":null,"homepage":"https://nuzulul.github.io/kv-storage/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nuzulul.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-30T03:39:18.000Z","updated_at":"2025-02-18T09:46:24.000Z","dependencies_parsed_at":"2024-01-30T10:45:35.154Z","dependency_job_id":"52078ba7-4d0a-4858-8190-f4c5c96690ca","html_url":"https://github.com/nuzulul/kv-storage","commit_stats":null,"previous_names":["nuzulul/kv-storage"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuzulul%2Fkv-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuzulul%2Fkv-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuzulul%2Fkv-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuzulul%2Fkv-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nuzulul","download_url":"https://codeload.github.com/nuzulul/kv-storage/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251859942,"owners_count":21655645,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare-workers","data-storage","data-store","database","db","file","file-database","file-storage","indexeddb","kv-storage","node-js","nodejs","nosql","nosql-database","storage"],"created_at":"2024-09-01T21:01:20.642Z","updated_at":"2025-05-01T10:31:35.236Z","avatar_url":"https://github.com/nuzulul.png","language":"TypeScript","funding_links":[],"categories":["nosql"],"sub_categories":[],"readme":"# kv-storage\n💾 Create data storage that uses a simple key-value method for Node, Browser, Deno, Bun, Cloudflare Workers\n\n[Demo](https://codesandbox.io/p/devbox/simple-kv-storage-pzr9ld)\n\n## Features\n\n* ✅ 0 Dependencies\n* ✅ NoSQL Database\n* ✅ Lightwight\n\n## Installation\n\nNPM (node, browser, deno, bun, cloudflare)\n```javascript\nnpm install kv-storage\n```\nCDN (browser)\n```javascript\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/kv-storage@0.0.9/dist/umd/kv-storage.js\"\u003e\u003c/script\u003e\n```\n\n## Initialization\n\nNPM\n\n```javascript\n//Node \u0026 Bun CommonJS import style\nconst {KVStorage} = require('kv-storage')\n\n//Node, Browser, Deno, Bun \u0026 Cloudflare ES Modules import style\nimport {KVStorage} from 'kv-storage'\n\n//Deno import style\nimport {KVStorage} from 'npm:kv-storage@0.0.9'\n\n//Node, Browser, Deno \u0026 Bun Initialization\nconst db = await KVStorage({\n\truntime:'node', //node | browser | deno | bun\n\tstorageName:'storage'\n})\n\n//Cloudflare Initialization\nconst db = await KVStorage({\n\truntime:'cloudflare',\n\tstorageName:'storage', //Cloudflare D1 database name\n\tdatabaseBinding:env.D1 //Cloudflare D1 database binding env\n})\n```\nCDN\n```javascript\n//Browser initialization if using CDN\n\nconst db = await KVStorage({\n\truntime:'browser',\n\tstorageName:'storage'\n})\n```\n\n## Example Usage\n\n```javascript\n//Node \u0026 Bun CommonJS example\nconst {KVStorage} = require('kv-storage')\n\nvoid async function main() {\n\tconst db = await KVStorage({\n\t\truntime:'node',//node | bun\n\t\tstorageName:'storage'\n\t})\n\t\n\tconsole.log(await db.put('key','value'))\n\tconsole.log(await db.get('key'))\n\tconsole.log(await db.list())\n\tconsole.log(await db.delete('key'))\n\tconsole.log(await db.has('key'))\n\tconsole.log(await db.clear())\n}()\n```\n\n```javascript\n//Node, Deno \u0026 Bun ES Modules example\nimport {KVStorage} from 'kv-storage'\n\nvoid async function main() {\n\tconst db = await KVStorage({\n\t\truntime:'node',//node | deno | bun\n\t\tstorageName:'storage'\n\t})\n\t\n\tconsole.log(await db.put('key','value'))\n\tconsole.log(await db.get('key'))\n\tconsole.log(await db.list())\n\tconsole.log(await db.delete('key'))\n\tconsole.log(await db.has('key'))\n\tconsole.log(await db.clear())\n}()\n```\n```javascript\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/kv-storage@0.0.9/dist/umd/kv-storage.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n//Browser using CDN example\n\nvoid async function main() {\n\tconst db = await KVStorage({\n\t\truntime:'browser',\n\t\tstorageName:'storage'\n\t})\n\t\n\tconsole.log(await db.put('key','value'))\n\tconsole.log(await db.get('key'))\n\tconsole.log(await db.list())\n\tconsole.log(await db.delete('key'))\n\tconsole.log(await db.has('key'))\n\tconsole.log(await db.clear())\n}()\n\u003c/script\u003e\n```\n\n```javascript\n\u003cscript type=\"module\"\u003e\n//Browser ES Modules example\nimport {KVStorage} from 'https://cdn.jsdelivr.net/npm/kv-storage@0.0.9/dist/mjs/kv-storage.js'\n\nvoid async function main() {\n\tconst db = await KVStorage({\n\t\truntime:'browser',\n\t\tstorageName:'storage'\n\t})\n\t\n\tconsole.log(await db.put('key','value'))\n\tconsole.log(await db.get('key'))\n\tconsole.log(await db.list())\n\tconsole.log(await db.delete('key'))\n\tconsole.log(await db.has('key'))\n\tconsole.log(await db.clear())\n}()\n\u003c/script\u003e\n```\n```javascript\n//Deno example\nimport {KVStorage} from 'npm:kv-storage@0.0.9'\n\nvoid async function main() {\n\tconst db = await KVStorage({\n\t\truntime:'deno',\n\t\tstorageName:'storage'\n\t})\n\t\n\tconsole.log(await db.put('key','value'))\n\tconsole.log(await db.get('key'))\n\tconsole.log(await db.list())\n\tconsole.log(await db.delete('key'))\n\tconsole.log(await db.has('key'))\n\tconsole.log(await db.clear())\n}()\n```\n\n```javascript\n//Cloudflare workers example\nimport {KVStorage} from 'kv-storage'\n\nexport default { \n\tasync fetch(request, env) { \n\n\t\tconst db = await KVStorage({\n\t\t\truntime:'cloudflare',\n\t\t\tstorageName:'storage', //Cloudflare D1 database name\n\t\t\tdatabaseBinding:env.D1 //Cloudflare D1 database binding env\n\t\t})\n\t\t\n\t\tlet data = []\t\t\n\t\tdata.push(await db.put('key','value'))\n\t\tdata.push(await db.get('key'))\n\t\tdata.push(await db.has('key'))\n\t\tdata.push(await db.list())\n\t\tdata.push(await db.delete('key'))\n\t\tdata.push(await db.clear())\n\t\treturn new Response(JSON.stringify(data, null, 2)) \n\t} \n}\n```\n\n## API Reference\n\n### Documentation\n\n[https://nuzulul.github.io/kv-storage/](https://nuzulul.github.io/kv-storage/)\n\n### Initialization parameters\n\n```javascript\nawait init({\n\truntime,\n\tstorageName,\n\tdatabaseBinding\n})\n```\n```\nruntime =  Javascript runtime \nstorageName = Alphanumeric storage name\ndatabaseBinding = Cloudflare only D1 database binding env\n```\nSupported runtime :\n- [x] `node` use File System\n- [x] `deno` use File System need `--allow-read --allow-write`\n- [x] `browser` use [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API)\n- [x] `bun` use File System\n- [x] `cloudflare` workers use D1 Database [docs](https://developers.cloudflare.com/d1/get-started/#4-bind-your-worker-to-your-d1-database) example [wrangler.toml](https://github.com/nuzulul/kv-storage/blob/main/wrangler.toml)\n\n### Write key-value pairs\n\n```javascript\nawait put(key,value)\n```\nThe put() method returns a Promise that you should await on to verify a successful update, resolve to `true` or `false`\n### Read key-value pairs\n\n```javascript\nawait get(key)\n```\nThe get() method returns a promise you can await on to get the value, resolve to the value or `false`\n\n### List keys\n\n```javascript\nawait list()\n```\nUse a list operation to view all the keys that live in a given storage, return a promise which resolves with an object consist of:\n* keys = Array of keys\n* complete = true if operation complete\n\n### Delete key-value pairs\n\n```javascript\nawait delete(key)\n```\n\nTo delete a key-value pair, call the delete() method, resolve to `true` or `false`\n\n### Has key-value pairs\n\n```javascript\nawait has(key)\n```\nTo check for the existence of a key, resolve to `true` or `false`\n\n### Clear storage\n\n```javascript\nawait clear()\n```\nTo delete all key value pairs, resolve to `true` or `false`\n\n\n## License\n\nMIT\n\n## Maintainers\n\n[Nuzulul Zulkarnain](https://github.com/nuzulul)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuzulul%2Fkv-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnuzulul%2Fkv-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuzulul%2Fkv-storage/lists"}