kv-orm-cf-workers
v0.2.3
Published
A Cloudflare Workers KV datastore plugin for kv-orm
Downloads
13
Maintainers
Readme
kv-orm-cf-workers
A Cloudflare Workers KV datastore plugin for kv-orm.
Note: Requires the latest Namespace version.
Installation
npm install --save kv-orm kv-orm-cf-workers
Setup
- Create a Namespace in Cloudflare, by either:
- Using the UI:
- In the Cloudflare Dashboard, navigate to the Workers tab:
- Under the Workers KV section, enter a name, and click
Add
:
- Using the API
- Using a deploy tool:
- Serverless
- Wrangler (Coming Soon!)
- Using the UI:
- Bind the Namespace to a variable in your script:
- Using the UI:
- Navigate to the Worker Editor:
- Select your Script, and go the the Resources tab.
- Click
+ Add Binding
, select your new Namespace, and clickSave
:
- Using the API
- Using a deploy tool:
- Using the UI:
- This makes the binded, global variable available within the Cloudflare Worker Script.
Note: It's recommended that you use an exclusive namespace for a kv-orm datastore i.e. don't manually store any data in that Namespace, at risk of having it overwritten by kv-orm.
Usage
import { BaseEntity, Column, Entity } from "kv-orm";
import { CloudflareWorkersKVDatastore } from "kv-orm-cf-workers";
// Bind a Cloudflare Namespace to a variable (see Setup above): e.g. LIBRARY
const cfWorkersKVDatastore = new CloudflareWorkersKVDatastore(LIBRARY);
@Entity(cfWorkersKVDatastore)
class Author extends BaseEntity {
@Column()
public firstName!: string;
@Column()
public lastName!: string;
}
// For more information how to then use Author, check out the kv-orm package:
// https://github.com/GregBrimble/kv-orm
Limitations
- [ ] Investigating Relationships
~~-to-many Relationships are limited to 4000 instances. It may be possible to overcome this limitation by having tree-like 'spaces' to contain multiple sets of children (untested!).~~