A small .NET class library that stores string key/value pairs in a SQLite database file.
- .NET 10 SDK
From the repository root:
dotnet build .\WebNet.KvStoreLite.slnx -nologoRun the full test suite with:
dotnet test .\WebNet.KvStoreLite.slnx -nologoRun a single test with:
dotnet test .\WebNet.KvStoreLite.Tests\WebNet.KvStoreLite.Tests.csproj -nologo --filter "FullyQualifiedName~GetValue_ReturnsValue_ForExistingSampleKey"The solution contains two projects:
WebNet.KvStoreLite- the SQLite-backed key/value store implementationWebNet.KvStoreLite.Tests- xUnit tests covering the current public API behavior with reusable sample data
KvStoreOptionsconfigures the database file name and base directoryKvStoreprovides collection creation, inserts, reads, and deletes
Each collection is stored as a SQLite table with two text columns:
k- keyv- value
The backing database file is created at:
<BaseDirectory>\<StoreName>.sqlitedb
using WebNet.KvStoreLite;
KvStoreOptions options = new()
{
StoreName = "app-data",
BaseDirectory = AppContext.BaseDirectory
};
using KvStore store = new(options);
store.CreateCollection("users");
store.Add(
"users",
new("alice", "admin"),
new("bob", "reader"));
string aliceRole = store.GetValue("users", "alice");
int removed = store.Remove("users", "bob");
var snapshot = store.GetCollection("users");Addcreates the collection automatically if it does not already exist.GetCollection,GetValue, andRemoverely on the internal command object having already been initialized. In practice, callCreateCollectionorAddbefore using those methods on a freshKvStoreinstance.- Missing values return
string.Empty. AddandRemovereturn the number of affected rows, or0when the operation does not run.- Keys and values are stored as strings only.
- Collection names are inserted directly into SQL statements and are therefore expected to come from trusted inputs.
- Tables do not enforce unique keys.
GetValuereturns the first matching row for a key.GetCollectionmaterializes rows into aReadOnlyDictionary<string, string>, so duplicate keys in a collection can cause dictionary population to fail.
- API comments live in
WebNet.KvStoreLite\KvStore.csandWebNet.KvStoreLite\KvStoreOptions.cs - Architecture notes live in
docs\architecture.md
The test project uses a small shared sample dataset:
- collection:
users - keys:
alice,bob,charlie - values:
admin,reader,editor
Each test creates its own temporary SQLite database directory so runs stay isolated from one another.