Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

RFC: KV put with metadata #1734

Closed
ags799 opened this issue Jan 15, 2021 · 7 comments · Fixed by #1740 or jacobwgillespie/saved-for-later#77
Closed

RFC: KV put with metadata #1734

ags799 opened this issue Jan 15, 2021 · 7 comments · Fixed by #1740 or jacobwgillespie/saved-for-later#77
Assignees

Comments

@ags799
Copy link
Contributor

ags799 commented Jan 15, 2021

💡 Feature request

Perform a KV put with metadata from Wrangler:

wrangler kv:key put my-key my-value --metadata '{"some": "json"}'

Any kind of JSON works:

  • boolean
  • number
  • object
  • array
  • strings
@ags799 ags799 changed the title kv put with metadata RFC: KV put with metadata Jan 15, 2021
@xtuc
Copy link
Member

xtuc commented Jan 18, 2021

accept almost any kind of JSON [...] not strings though

does it mean

wrangler kv:key put my-key my-value --metadata '1'

is supported but not

wrangler kv:key put my-key my-value --metadata '"json"'

@ags799
Copy link
Contributor Author

ags799 commented Jan 19, 2021 via email

@koeninger
Copy link
Contributor

Why? Doing e.g. the following from a worker is fine:

    await NS.put(key, value, {metadata: "some_string"})

@xtuc

This comment has been minimized.

@koeninger
Copy link
Contributor

the third argument isn't metadata, it's an options object that may contain a metadata key. See https://developers.cloudflare.com/workers/runtime-apis/kv#metadata and https://github.com/cloudflare/workers-types/blob/master/index.d.ts#L610

My example above would result in

    const { value, metadata } = await NS.getWithMetadata(key);

binding metadata to "some_string", not {metadata: "some_string"}

@xtuc
Copy link
Member

xtuc commented Jan 19, 2021

Indeed, thanks for clarify. I hidden my comment since it's not relevant

@ags799
Copy link
Contributor Author

ags799 commented Jan 19, 2021

Why? Doing e.g. the following from a worker is fine:

    await NS.put(key, value, {metadata: "some_string"})

Never mind, I wasn't escaping quotes correctly in my curl command. The API will accept strings just fine.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.