JsonDatabase is a lightweight, human-readable database solution for .NET projects. It uses JSON for data storage, providing a simple way to store, retrieve, and manipulate objects in a file-based database. The database is highly performant and supports partial updates, making it ideal for applications that require a fast and easy-to-use storage layer.
- Human-readable storage: Data is stored in JSON format, making it easy to read and debug.
- Simple API: Store, retrieve, and delete objects with minimal setup.
- Partial updates: Supports efficient updates to specific parts of the database file.
- Typed operations: Operate directly on your classes without additional mapping layers.
- File-based: Uses the local file system, with no external dependencies or server setup.
To install Ck.Database, add the NuGet package to your project.
Install-Package Ck.Database -Version 1.0.0dotnet add package Ck.Database --version 1.0.0Add the following line to your .csproj file:
<PackageReference Include="Ck.Database" Version="1.0.0" />For more information, visit the Ck.Database NuGet page.
Set up the database by specifying a directory for data storage:
var Path = @"C:\TEMP\TestDb";
var JsonDatabase = new JsonDatabase(Path);Create objects to store in the database:
var foo = new Foo
{
Name = "Carlos's World",
Bar = new Bar
{
Street = "Weezenhof 6134",
Drink = new Drink { Name = "White wine" }
},
Somethings = new List<Drink>
{
new Drink { Name = "Gin & Tonic" },
new Drink { Name = "Beer" },
new Drink { Name = "Whiskey" },
}
};
JsonDatabase.Store(foo);Remove specific objects from the database by their type and Id:
var whiskeyId = foo.Somethings[2].Id;
JsonDatabase.Delete<Drink>(whiskeyId);
foo.Somethings.Remove(2);Here’s an example of the classes used in the database:
public class Foo
{
public string Name { get; set; }
public Bar Bar { get; set; }
public List<Drink> Somethings { get; set; }
}
public class Bar
{
public string Street { get; set; }
public Drink Drink { get; set; }
}
public class Drink
{
public string Name { get; set; }
public Guid Id { get; set; } = Guid.NewGuid(); // Ensure each object has a unique identifier
}JsonDatabase focuses on simplicity and ease of use:
- No complex schema definitions.
- Clear and concise API for rapid development.
- Transparent file-based storage.
Contributions to JsonDatabase are welcome! Please submit issues or pull requests through the GitHub repository.
This project is licensed under the MIT License. See the LICENSE file for details.
Happy coding! 😊