Skip to content

Zig: NBT and the key-value database

kvdb.KvDb

Zig
1
2
3
4
pub const KvDb = struct {
    handle: c.PierKvDbHandle,
    // ...
};

One open key-value store. close releases it.

kvdb.KvDb.open

Zig
pub fn open(path: []const u8) core.Error!KvDb

Opens it, creating it when it does not exist.

  • Parameters:
    • path : []const u8
  • Return type: core.Error!KvDb

kvdb.KvDb.openExisting

Zig
pub fn openExisting(path: []const u8) core.Error!KvDb

Opens an existing one only. A store that does not exist is Refused and no empty one is created in its place.

  • Parameters:
    • path : []const u8
  • Return type: core.Error!KvDb

kvdb.KvDb.close

Zig
pub fn close(self: *KvDb) void

Closes the store; calling it twice is harmless.

kvdb.KvDb.get

Zig
pub fn get(self: KvDb, allocator: Allocator, key: []const u8) core.Error!?[]u8

Reads one key, owned by the caller: null for a key that does not exist.

  • Parameters:
    • allocator : Allocator
    • key : []const u8
  • Return type: core.Error!?[]u8
  • Slots: kvdb_get

kvdb.KvDb.set

Zig
pub fn set(self: KvDb, key: []const u8, value: []const u8) core.Error!void
  • Parameters:
    • key : []const u8
    • value : []const u8
  • Return type: core.Error!void
  • Slots: kvdb_set

kvdb.KvDb.del

Zig
pub fn del(self: KvDb, key: []const u8) core.Error!void

Deletes one key. A key that never existed also counts as a success.

  • Parameters:
    • key : []const u8
  • Return type: core.Error!void
  • Slots: kvdb_del

kvdb.KvDb.has

Zig
pub fn has(self: KvDb, key: []const u8) core.Error!bool
  • Parameters:
    • key : []const u8
  • Return type: core.Error!bool
  • Slots: kvdb_has

kvdb.KvDb.isEmpty

Zig
pub fn isEmpty(self: KvDb) core.Error!bool

kvdb.KvDb.pairs

Zig
pub fn pairs(self: KvDb, allocator: Allocator) core.Error!types.Owned(Pair)

Every key and value. The whole store is read into memory, so a large one needs care.

  • Parameters:
    • allocator : Allocator
  • Return type: core.Error!types.Owned(Pair)
  • Slots: kvdb_iter

kvdb.Pair

Zig
1
2
3
4
5
pub const Pair = struct {
    key: []const u8,
    value: []const u8,
    // ...
};

One key and its value.