A simple key-value store implemented in Zig. Stores can be read and written to disk.
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.
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
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");
}
todo