SLVZ.Db
1.21.0
dotnet add package SLVZ.Db --version 1.21.0
NuGet\Install-Package SLVZ.Db -Version 1.21.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SLVZ.Db" Version="1.21.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SLVZ.Db" Version="1.21.0" />
<PackageReference Include="SLVZ.Db" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SLVZ.Db --version 1.21.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SLVZ.Db, 1.21.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SLVZ.Db@1.21.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SLVZ.Db&version=1.21.0
#tool nuget:?package=SLVZ.Db&version=1.21.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
π¦ 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 file β perfect for small projects, configs, or apps that donβt require a real database.
1. Database context (Fast and good for millions of records)
First lets create a model
using SLVZ.Db;
enum Role
{
Admin,
User
}
class myModel
{
[PrimaryKey] //Defines the unique key used by the database to identify the record
public Int64 ID { get; set; }
public string Name { get; set; }
public Role Role { get; set; }
public double Grade { get; set; }
public bool IsActive { get; set; }
}
Attribute PrimaryKey is necessary
Create Your Database Context
using SLVZ.Db;
class myDB : DbContext
{
public override void Configuration()
{
// Argument: Database file full path
Initialize($"{Environment.CurrentDirectory}/database.db");
Mdl1 = DataSet<myModel1>();
Mdl1 = DataSet<myModel2>();
Mdl1 = DataSet<myModel3>();
}
public DataSet<myModel1>? Mdl1;
public DataSet<myModel2>? Mdl2;
public DataSet<myModel3>? Mdl3;
}
Example Usage
using SLVZ.Db;
var db = new myDB();
var id_1 = await db.Mdl1.Add(new myModel1(...));
var id_2 = await db.Mdl2.Add(new myModel2(...));
var id_3 = await db.Mdl3.Add(new myModel3(...));
//Get all records
var models = await db.Mdl1.All();
//Find a record
var model = await db.Mdl1.Find([Int64.PrimaryKey]);
//Find a range of primary keys
var model = await db.Mdl1.Find(x => x.ID > 10 && x.ID < 20);
//Remove a record
await db.Mdl1.Remove([Int64.PrimaryKey]);
await db.Mdl1.Remove(YourModel);
//Remove a list of records
await db.Mdl1.Remove(ListModels);
//Update a record
await db.Mdl1.Update(YourModel);
//Update a list of records
await db.Mdl1.Update(ListModels);
//Filter records based of given condition
var models = await db.Mdl1.Where(x => x.Name.Contains("Text"));
//Determines whether any record matches the given condition
bool result = await db.Mdl1.Any(x => x.Name.Contains("Text"));
2. Light database context (Light and good for small jobs)
First lets create a model
using SLVZ.Db.Light;
enum Role
{
Admin,
User
}
class myModel
{
[Key] //Defines the unique key used by the database to identify the record
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; }
}
Attribute Key is necessary
Create Your Database Context
using SLVZ.Db.Light;
class myDB : LightContext
{
public override void Configuration()
{
Mdl1 = DataSet<myModel1>("{Path}/model1.db");
Mdl1 = DataSet<myModel2>("{Path}/model2.db");
Mdl1 = DataSet<myModel3>("{Path}/model3.db");
// Argument: Database file full path
}
public DataSet<myModel1>? Mdl1;
public DataSet<myModel2>? Mdl2;
public DataSet<myModel3>? Mdl3;
}
Example Usage
using SLVZ.Db.Light;
var db = new myDB();
await db.Mdl1.Add(new myModel1(...));
await db.Mdl2.Add(new myModel2(...));
await db.Mdl3.Add(new myModel3(...));
//Add a list of models
await db.Mdl1.Add(new List<myModel1>());
//Get all records
var models = await db.Mdl1.All();
//Find a record
var model = await db.Mdl1.Find("Your key");
//Remove a record
await db.Mdl1.Remove("Your key");
await db.Mdl1.Remove(YourModel);
//Remove a list of records
await db.Mdl1.RemoveRange(ListModels);
//Update a record
await db.Mdl1.Update(YourModel);
//Update a list of records
await db.Mdl1.UpdateRange(ListModels);
//Filter records based of given condition
var models = await db.Mdl1.Where(x => x.Name.Contains("Text"));
//Determines whether any record matches the given condition
bool result = await db.Mdl1.Any(x => x.Name.Contains("Text"));
π¨βπ» 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
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.