Skip to content

coffee-cup/zig-kv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zig key-value store

CI

A simple key-value store implemented in Zig. Stores can be read and written to disk.

CLI

You can use the CLI to interact with the key-value store.

> kv --help
Save key-value pairs to a file.
    -h, --help
            Display this help and exit.

    -f, --file <str>
            The file to read and write the key-value pairs. Defaults to ~/.kv.json.

    <str>...
            The key-value pairs to add to the file. e.g. key1 value1 key2 value2.

Examples

Set key-value pairs in the store:

# Sets hello=world and one=1 in the store
# Saves the store to the default location on disk (~/.kv.json)
kv hello world one 1

Get a single item from the store:

# Gets the value of the key hello
kv hello

Use a non-default file location

kv -f test.json hello world one 1
kv -f test.json hello

Usage

You can use the key-value store in your Zig code.

pub fn main() !void {
  var gpa = std.heap.GeneralPurposeAllocator(.{}){};
  defer _ = gpa.deinit();

  const allocator = gpa.allocator();

  var kv = Kv.init(allocator);
  defer kv.deinit();

  // Load key-value pairs from a file (this is optional)
  try kv.load("test.json");

  // Set and get a few values
  try kv.put("hello", "world");
  try kv.put("one", "1");
  _ = try kv.get("hello");

  // Save the key-value pairs to a file (also optional)
  try kv.save("test.json");
}

Installation

todo

About

A simple key value store written in Zig

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages