Skip to content

Commit 0716bd4

Browse files
Jake ChampionJakeChampion
authored andcommitted
add documentation for KVStore.prototype.delete
1 parent 748b151 commit 0716bd4

File tree

1 file changed

+61
-0
lines changed
  • documentation/docs/fastly:kv-store/KVStore/prototype

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
# KVStore.prototype.delete
8+
9+
Deletes the value associated with the key `key` in the KV store.
10+
11+
## Syntax
12+
13+
```js
14+
delete(key)
15+
```
16+
17+
### Parameters
18+
19+
- `key` _: string_
20+
- The key to retrieve from within the KV-store.
21+
22+
### Return value
23+
24+
Returns `undefined`
25+
26+
### Exceptions
27+
28+
- `TypeError`
29+
- If the provided `key`:
30+
- Is any of the strings `""`, `"."`, or `".."`
31+
- Starts with the string `".well-known/acme-challenge/"`
32+
- Contains any of the characters `"#?*[]\n\r"`
33+
- Is longer than 1024 characters
34+
35+
## Examples
36+
37+
In this example we connect to an KV Store named `'files'` and save an entry to the store under the key `'hello'` and then delete the entry.
38+
39+
```js
40+
/// <reference types="@fastly/js-compute" />
41+
42+
import { KVStore } from "fastly:kv-store";
43+
44+
async function app(event) {
45+
const files = new KVStore('files')
46+
47+
await files.put('hello', 'world')
48+
await files.delete('hello')
49+
50+
const entry = await files.get('hello')
51+
if (entry) {
52+
return new Response(await entry.text())
53+
} else {
54+
return new Response('no file named hello exists')
55+
}
56+
57+
}
58+
59+
addEventListener("fetch", (event) => event.respondWith(app(event)))
60+
61+
```

0 commit comments

Comments
 (0)