Skip to content

Cloudflare workers KV with customizable backing store for testing.

License

Notifications You must be signed in to change notification settings

alanshaw/cf-workers-kv

Repository files navigation

cf-workers-kv

Build Status dependencies Status

Cloudflare workers KV with customizable backing store for testing.

Install

npm install cf-workers-kv

Usage

import { KV } from 'cf-workers-kv'

// In memory map backend, also supports AsyncMapLike inerface for backing stores
// with async get/put etc. https://npm.im/async-map-like
const backend = new Map()
const fruits = new KV(backend)

const key = 'apple:grannysmith'
const value = { name: 'Granny Smith', type: 'apple', color: 'green' }
const metadata = { name: 'Granny Smith' }

await fruits.put(key, JSON.stringify(value), { metadata })

const apple = await fruits.get(key, 'json')
console.log(apple) // { name: 'Granny Smith', type: 'apple', color: 'green' }

const apples = await fruits.list({ prefix: 'apple:' })
console.log(apples) // { keys: [{ name: 'apple:grannysmith', metadata: { name: 'Granny Smith' } }], list_complete: true }

await fruits.delete(key)

API

See Cloudflare Workers Runtime API docs.

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Alan Shaw

About

Cloudflare workers KV with customizable backing store for testing.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published