SLVZ.Db
1.15.0
See the version list below for details.
dotnet add package SLVZ.Db --version 1.15.0
NuGet\Install-Package SLVZ.Db -Version 1.15.0
<PackageReference Include="SLVZ.Db" Version="1.15.0" />
<PackageVersion Include="SLVZ.Db" Version="1.15.0" />
<PackageReference Include="SLVZ.Db" />
paket add SLVZ.Db --version 1.15.0
#r "nuget: SLVZ.Db, 1.15.0"
#:package SLVZ.Db@1.15.0
#addin nuget:?package=SLVZ.Db&version=1.15.0
#tool nuget:?package=SLVZ.Db&version=1.15.0
π¦ SLVZ Db, Simple Local File Database for C#
A lightweight, dependency-free library for storing and retrieving data locally in a file.
This works like a very simplified ORM (similar to EF Core) but stores data in a plain text file β perfect for small projects, configs, or apps that donβt require a real database.
Features
- Store and retrieve data without an external database
- Supports primitive data types (
int,string,bool,double,enum, ...) - Full CRUD operations (
Append,Get,Update,Remove) - Data stored in a human-readable plain text format
- Supports multiple models with separate database classes
How to Use
1. Create Your Data Model
enum Role
{
Admin,
User
}
class myModel
{
public int ID { get; set; }
public string Name { get; set; }
public Role Role { get; set; }
public double Grade { get; set; }
public bool IsActive { get; set; }
}
2. Create Your Database Context
class myDB : DbContext<myModel>
{
public override void Configuration()
{
SetConfig($"{Environment.CurrentDirectory}/slvz.db", "ID", "AES_KEY");
// First argument: Database file full path
// Second argument: Property name to be used as the unique key
// Third argument: This is optional, If you want your database be encrypted, add AES_KEY to the third argument
}
}
3. Example Usage
var db = new myDB();
// Add 3 users
await db.Append(new myModel
{
ID = 1,
Name = "Ashkan",
Grade = 19.234,
IsActive = true,
Role = Role.Admin
});
await db.Append(new myModel
{
ID = 2,
Name = "Arash",
Grade = 21.992,
IsActive = true,
Role = Role.User
});
await db.Append(new myModel
{
ID = 3,
Name = "Baran",
Grade = 18.224452,
IsActive = false,
Role = Role.User
});
// Get all models
var models = await db.Get();
// Modify one model
models.Find(x => x.ID == 3).IsActive = true;
// Update it in the database
await db.Update(models.Find(x => x.ID == 3));
// Delete a model
// await db.Remove(3);
// Get a single model by ID
var model = await db.Get(3);
Console.WriteLine("Done");
API Reference
Append(TModel model)
Adds a single model to the database file.
- Parameters:
modelβ An instance of your model. Must match the configured model type.
Append(List<TModel> models)
Adds multiple models to the database at once.
- Parameters:
modelsβ A list of model instances. All must match the configured model type.
List<TModel> Get()
Retrieves all models stored in the database.
- Returns:
A list of all models. Returns an empty list if no data file exists.
TModel Get(T id)
Retrieves a single model by its key property.
Parameters:
keyβ The value of the key property to search for.Returns:
The model matching the key, or a new default instance if not found.
Update(TModel model)
Updates an existing model in the database.
- Parameters:
modelβ The updated model instance. The key property must match an existing entry.
AvailablePrimaryKey(List<T> recordKeys)
Return the first available primary key from database. You can send it a list if id's and it will return you the first ID that hasn't used
Remove(T id)
Deletes a model from the database by its key.
- Parameters:
keyβ The key value of the model to delete.
π¨βπ» Author: SLVZ
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.