Try   HackMD

KV Collaboration Deck

interface "wasi:kv/data/readwrite" {
  use { Error, payload, key } from "wasi:kv/types"

  // Get retrieves the value associated with the given key. It returns an Error if the key does not exist.
  get: func(key: key) -> result<payload, Error>

  // set creates a new key-value pair or updates an existing key-value pair.
  set: func(key: key, value: stream<u8>) -> result<_, Error>

  // delete a key-value pair. If the key does not exist, it returns an Ok() result.
  delete: func(key: key) -> result<_, Error>

  // check if the key exists.
  exists: func(key: key) -> result<bool, Error>
}

Passing a pseudo-handles for a specific connection

interface "wasi:kv/data/readwrite" {
  use { Error, payload, key } from "wasi:kv/types"

  // Open retrieves the kv-handle
  open: func(connection-string: string) -> result<kv-handle, Error>
  
  // Get retrieves the value associated with the given key. It returns an Error if the key does not exist.
  get: func(handle: kv-handle, key: key) -> result<payload, Error>

  // set creates a new key-value pair or updates an existing key-value pair.
  set: func(handle: kv-handle, key: key, value: stream<u8>) -> result<_, Error>

  // delete a key-value pair. If the key does not exist, it returns an Ok() result.
  delete: func(handle: kv-handle, key: key) -> result<_, Error>

  // check if the key exists.
  exists: func(handle: kv-handle, key: key) -> result<bool, Error>
}

Passing a string for a specific connection

interface "wasi:kv/data/readwrite" {
  use { Error, payload, key } from "wasi:kv/types"

  // Get retrieves the value associated with the given key. It returns an Error if the key does not exist.
  get: func(handle: string, key: key) -> result<payload, Error>

  // set creates a new key-value pair or updates an existing key-value pair.
  set: func(handle: string, key: key, value: stream<u8>) -> result<_, Error>

  // delete a key-value pair. If the key does not exist, it returns an Ok() result.
  delete: func(handle: string, key: key) -> result<_, Error>

  // check if the key exists.
  exists: func(handle: string, key: key) -> result<bool, Error>
}

Example SDK experiences

// pseudo-handles:
conn = kv::open("foo")
val = kv::get(conn, "k")

// labels
val = kv::get("foo", "k")

// future star imports
kv::foo::get("k")