Unleasharp.DB.Base
1.3.0
See the version list below for details.
dotnet add package Unleasharp.DB.Base --version 1.3.0
NuGet\Install-Package Unleasharp.DB.Base -Version 1.3.0
<PackageReference Include="Unleasharp.DB.Base" Version="1.3.0" />
<PackageVersion Include="Unleasharp.DB.Base" Version="1.3.0" />
<PackageReference Include="Unleasharp.DB.Base" />
paket add Unleasharp.DB.Base --version 1.3.0
#r "nuget: Unleasharp.DB.Base, 1.3.0"
#:package Unleasharp.DB.Base@1.3.0
#addin nuget:?package=Unleasharp.DB.Base&version=1.3.0
#tool nuget:?package=Unleasharp.DB.Base&version=1.3.0
Unleasharp.DB.Base
A lightweight, database-agnostic library for .NET that provides connection management, query building, and data serialization capabilities.
๐ฏ Key Concepts
This library provides a foundation for database operations with the following core features:
๐ Connection Handling
- Automatic connection creation and management
- Configurable automatic connection regeneration after specified intervals
- Ensures database connections are always open and ready for use
๐งต Threading Support
- Thread-safe connection management through
ConnectorManager
- Each thread receives its own dedicated database connection instance
๐ Query Generation
- Query class: Holds SQL query parameters in an engine-agnostic manner
- QueryBuilder class: Executes queries against the database and maps results to specified types
- Follows fluent interface pattern for intuitive query building
๐ Serialization
- Automatic mapping of database results to C# objects using generic type parameters
- Supports both simple class mapping and attribute-based schema definitions
๐ง Query Generation Architecture
The library follows a CRTP (Curiously Recurring Template Pattern) approach where:
- The base
Query
class provides engine-agnostic functionality - Engine-specific implementations handle the actual SQL rendering
- Query building follows standard SQL syntax with fluent method chaining
๐ ๏ธ Connection Initialization
Using Connection String
var connector = new ConnectorManager("Server=localhost;Database=unleasharp;Uid=unleasharp;Pwd=unleasharp;");
Using Fluent Configuration
var connector = new ConnectorManager()
.WithAutomaticConnectionRenewal(true)
.WithAutomaticConnectionRenewalInterval(TimeSpan.FromHours(1))
.Configure(config => {
config.ConnectionString = "Server=localhost;Database=unleasharp;Uid=unleasharp;Pwd=unleasharp;";
});
Engine-Specific Connection Builder
// MySQL example
var connector = new ConnectorManager(
new MySqlConnectionStringBuilder("Server=localhost;Database=unleasharp;Uid=unleasharp;Pwd=unleasharp;")
);
โ๏ธ Configuration Options
Connection Management
The connections are automatically renewed by default, but automatic connection renewal behaviour can be adjusted.
connector.WithAutomaticConnectionRenewal(true)
.WithAutomaticConnectionRenewalInterval(TimeSpan.FromHours(1))
๐ Querying Examples
One-liner Execution
var rows = DBConnector.QueryBuilder()
.Build(query => query.Select().From("example_table"))
.ToList<ExampleTable>();
Standalone Query Generation
var standaloneQuery = Query.GetInstance()
.Select()
.From("example_table");
var rows = DBConnector.QueryBuilder(standaloneQuery)
.ToList<ExampleTable>();
Available Query Operations
// Select all fields from a table
Query.Select().From("example_table");
// Select with type mapping
Query.Delete().From<ExampleTable>().Where("id", 5);
// Insert single value
Query.Insert().Into("example_table").Value(new ExampleTable());
// Insert multiple values at once
Query.Insert()
.Into("example_table")
.Values(new List<ExampleTable> {
new ExampleTable(),
new ExampleTable()
});
๐๏ธ Database Structure Definitions
Simple Class Mapping (1:1)
public class example_table {
public ulong? id { get; set; }
public string _mediumtext { get; set; }
public string _longtext { get; set; }
public string _json { get; set; }
public byte[] _longblob { get; set; }
public EnumExample? _enum { get; set; }
public string _varchar { get; set; }
}
Attribute-Based Schema Definition
using System.ComponentModel;
using Unleasharp.DB.Base.SchemaDefinition;
[Table("example_table")]
[PrimaryKey("id")]
[UniqueKey("id", "id", "_enum")]
public class ExampleTable {
[Column("id", ColumnDataType.UInt64, Unsigned = true, PrimaryKey = true, AutoIncrement = true, NotNull = true)]
public ulong? Id { get; set; }
[Column("_mediumtext", ColumnDataType.Text)]
public string MediumText { get; set; }
[Column("_longtext", ColumnDataType.Text)]
public string Longtext { get; set; }
[Column("_json", ColumnDataType.Json)]
public string Json { get; set; }
[Column("_longblob", ColumnDataType.Binary)]
public byte[] CustomFieldName { get; set; }
[Column("_enum", ColumnDataType.Enum)]
public EnumExample? Enum { get; set; }
[Column("_varchar", "varchar", Length = 255)]
public string Varchar { get; set; }
}
Enum Value Handling
Important Considerations:
- Database engines treat enum values starting from 1, while C# enums start from 0
- Recommendation: Use a
NONE
value as the first enum member or set the first C# enum value to 1
Option 1: NONE as First Value
public enum EnumExample {
NONE,
Y,
[Description("NEGATIVE")]
N
}
Option 2: Explicit First Value
public enum EnumExample {
Y = 1,
[Description("NEGATIVE")]
N
}
The [Description]
attribute maps the C# enum value to its database representation.
๐ Database Engine Implementations
- โ MySQL - Unleasharp.DB.MySQL
- โ SQLite - Unleasharp.DB.SQLite
- โ PostgreSQL - Unleasharp.DB.PostgreSQL
- ๐ง MSSQL - Work in Progress
๐ฆ Dependencies
- Unleasharp - Multipurpose library
๐ Version Compatibility
This library targets .NET 8.0 and later versions. For specific version requirements, please check the package dependencies.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- Microsoft.CSharp (>= 4.7.0)
- Unleasharp (>= 1.0.2)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on Unleasharp.DB.Base:
Package | Downloads |
---|---|
Unleasharp.DB.MySQL
Lightweight MySQL query-building client for C#. |
|
Unleasharp.DB.SQLite
Lightweight SQLite query-building client for C#. |
|
Unleasharp.DB.PostgreSQL
Lightweight PostgreSQL query-building client for C#. |
|
Unleasharp.DB.MSSQL
Lightweight MSSQL query-building client for C#. |
|
Unleasharp.DB.DuckDB
Lightweight DuckDB query-building client for C#. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.7.1 | 53 | 9/14/2025 |
1.7.0 | 145 | 9/11/2025 |
1.6.0 | 149 | 9/3/2025 |
1.5.5 | 152 | 9/1/2025 |
1.5.4 | 122 | 9/1/2025 |
1.5.3 | 170 | 8/31/2025 |
1.5.2 | 174 | 8/30/2025 |
1.5.1 | 143 | 8/30/2025 |
1.5.0 | 196 | 8/28/2025 |
1.4.1 | 197 | 8/28/2025 |
1.4.0 | 193 | 8/28/2025 |
1.3.3 | 207 | 8/26/2025 |
1.3.2 | 152 | 8/25/2025 |
1.3.1 | 156 | 8/25/2025 |
1.3.0 | 144 | 8/25/2025 |
1.2.0 | 93 | 8/22/2025 |
1.1.1 | 133 | 8/21/2025 |
1.1.0 | 133 | 8/20/2025 |
1.0.2 | 132 | 8/20/2025 |
1.0.1 | 130 | 8/20/2025 |
1.0.0 | 128 | 8/19/2025 |