OxL Reference

data Kv

Handle of an open store.

Example:

oxl✓ checked in CI
use std.kv { Kv }

fn main() io, db {
  let kv = Kv.open("docs-kv")!
  kv.put("greeting", b"hello")!
  print("{kv.get("greeting")!.len()}")
  kv.close()
}
Output
5
@derive(Copy)
pub(api) data Kv

Thread safety. a handle may be shared by tasks; single operations are linearizable.

Since. 1.0.0-beta

Fields

pub(api) h: i64

Handle of the store in the runtime.

Methods

reading(mode: Consistency, maxStale: Duration) -> Kv
A handle on the same store whose get and scan use mode (writes and transactions are not affected
open(name: str) -> Kv | KvError db
Opens (creates) the store name; "name?shards=4" (or $OXL_KV_SHARDS) sets the number of shards (default 1).
close() db
Closes the handle; later calls on it fail.
get(key: str) -> bytes? | KvError db
The value of key, or none.
getEntry(key: str) -> KvEntry? | KvError db
The value and version of key, or none.
version(key: str) -> u64 | KvError db
The version of key (0 = absent).
put(key: str, value: bytes) -> () | KvError db
Stores value under key.
delete(key: str) -> () | KvError db
Removes key; a missing key is not an error.
putIf(key: str, value: bytes, version: u64) -> bool | KvError db
Compare-and-set
scan(prefix: str, limit: i64) -> List<KvEntry> | KvError db
Entries whose key starts with prefix, ascending; at most limit (0 = all).
scanAfter(prefix: str, after: str, limit: i64) -> List<KvEntry> | KvError db
Like scan, continuing strictly after the key after (paging).
txn(body: fn(KvTx) -> R F) -> R | KvError db, F
Runs body in an optimistic transaction
watch(prefix: str) -> stream<KvEvent, KvError> db
The changes to keys with this prefix from now on, in commit order per shard.

Defined in: std/kv/kv.oxl:205

See also