senioi / KVLite

Persistant Key-Value and Key-Json Store based on SQLite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is KVLite

KVLite is a Key-Value Store based on SQLite. More specifically it uses 128 SQLite Databases which are addressed by the hashed key. For the hashing the FNV Hash function is used. KVLite has also special functions to interact with Json directly in the SQLite Database based on the SQLite Json1 Extension.

Basic Usage

var kvl = KVLite.CreateInDirectory(new DirectoryInfo("/my/path"));
var key = Encoding.UTF8.GetBytes("key");
var value = Encoding.UTF8.GetBytes("value");
var newValue = Encoding.UTF8.GetBytes("newValue");

await kvl.Add(key, value);
var res = await kvl.Get(key);
await kvl.Update(key, newValue);
await kvl.Delete(key);

Basic Json Usage

var kvl = KVLite.CreateJsonInDirectory(new DirectoryInfo("/my/path"));
var key = Encoding.UTF8.GetBytes("key");
var value = JsonSerializer.Serialize(new {hello = "value"});
var newValue = JsonSerializer.Serialize(new {hello = "newValue"});

await kvl.Add(key, value);
var res = await kvl.Get(key);
await kvl.Update(key, newValue);
await kvl.Delete(key);

Json Extension Usage

var kvl = KVLite.CreateJsonInDirectory(new DirectoryInfo("/my/path"));
var key = Encoding.UTF8.GetBytes("key");
var value = JsonSerializer.Serialize(new {hello = "value"});

await kvl.Add(key, value);// {"hello": "value"}
await kvl.Insert(key, "$.world", "value"); // {"hello": "value", "world": "value"}
await kvl.Replace(key, "$.hello", "newValue");// {"hello": "newValue", "world": "value"}
await kvl.Set(key, "$.hello", "[1,2,3]");// {"hello": [1,2,3], "world": "value"}
await kvl.Insert(key, "$.hello[#]", 4); // {"hello": [1,2,3,4], "world": "value"}

About

Persistant Key-Value and Key-Json Store based on SQLite

License:MIT License


Languages

Language:C# 100.0%