Skip to content

Repository files navigation

Welcome to @kv-orm/cf-workers 👋

GitHub Actions ChecksLGTM AlertsSynk VulnerabilitiesCodecovLGTM Code QualityCode Climate MaintainabilityVersionLicenseTypesGitHub Last Commit

A Cloudflare Workers KV datastore plugin for kv-orm.

Author

👤 Greg Brimble

🤝 Contributing

Contributions, issues and feature requests are welcome! Feel free to check issues page.

😍 Show your support

Please consider giving this project a ⭐️ if you use it, or if it provides some inspiration!

Usage

Install

npm install --save @kv-orm/core @kv-orm/cf-workers
npm install --save-dev @cloudflare/workers-types

Quick Start

import{KVNamespace}from"@cloudflare/workers-types";import{CloudflareWorkersKVDatastore}from"@kv-orm/cf-workers";import{Entity}from"@kv-orm/core";declare global {constmyKVNamespaceBinding: KVNamespace;}constdatastore=newCloudflareWorkersKVDatastore(myKVNamespaceBinding);
@Entity({ datastore })classMyEntity{// ...}

Options

The constructor can also take a couple of options:

  • keySeparator defaults to a colon, :
  • optionsGenerator, for a given key and value can return options to pass to the KV Namespace put method: expiration or expirationTtl. More information about expiring data can be found on the official Cloudflare documentation.
constdatastore=newCloudflareWorkersKVDatastore(myKVNamespaceBinding,{keySeparator: ":",optionsGenerator: (key,value)=>({expirationTtl: 120,// Or, alternatively, `expiration`}),});

In this particular example, all data will expire after 120 seconds.

Note: this expiration only affects data from new read/search operations. Data already in the memory cache will persist until purged (if using within a Worker context, this is until the end of the single request).

Development

Clone and Install Dependencies

git clone git@github.com:kv-orm/cf-workers.git
npm install

Run tests

npm run lint # 'npm run lint:fix' will automatically fix most problems
npm test

📝 License

Copyright © 2019 Greg Brimble.
This project is MIT licensed.

About

A Cloudflare Workers KV datastore plugin for kv-orm

Resources

Code of conduct

Stars

27 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages