Unleasharp.DB.MySQL 1.3.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Unleasharp.DB.MySQL --version 1.3.1
                    
NuGet\Install-Package Unleasharp.DB.MySQL -Version 1.3.1
                    
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="Unleasharp.DB.MySQL" Version="1.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Unleasharp.DB.MySQL" Version="1.3.1" />
                    
Directory.Packages.props
<PackageReference Include="Unleasharp.DB.MySQL" />
                    
Project file
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 Unleasharp.DB.MySQL --version 1.3.1
                    
#r "nuget: Unleasharp.DB.MySQL, 1.3.1"
                    
#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 Unleasharp.DB.MySQL@1.3.1
                    
#: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=Unleasharp.DB.MySQL&version=1.3.1
                    
Install as a Cake Addin
#tool nuget:?package=Unleasharp.DB.MySQL&version=1.3.1
                    
Install as a Cake Tool

🐬 Unleasharp.DB.MySQL

NuGet version (Unleasharp.DB.MySQL)

Unleasharp.DB.MySQL

MySQL implementation of Unleasharp.DB.Base. This repository provides a MySQL-specific implementation that leverages the base abstraction layer for common database operations.

📦 Installation

Install the NuGet package using one of the following methods:

Package Manager Console

Install-Package Unleasharp.DB.MySQL

.NET CLI

dotnet add package Unleasharp.DB.MySQL

PackageReference (Manual)

<PackageReference Include="Unleasharp.DB.MySQL" Version="1.3.1" />

🎯 Features

  • MySQL-Specific Query Rendering: Custom query building and rendering tailored for MySQL
  • Connection Management: Robust connection handling through ConnectorManager
  • Query Builder Integration: Seamless integration with the base QueryBuilder
  • Schema Definition Support: Full support for table and column attributes

🚀 Connection Initialization

The ConnectorManager handles database connections. You can initialize it using a connection string or MySqlConnectionStringBuilder.

Using Connection String

ConnectorManager DBConnector = new ConnectorManager("Server=localhost;Database=unleasharp;Uid=unleasharp;Pwd=unleasharp;");

Using Fluent Configuration

ConnectorManager DBConnector = new ConnectorManager()
    .WithAutomaticConnectionRenewal(true)
    .WithAutomaticConnectionRenewalInterval(TimeSpan.FromHours(1))
    .Configure(config => {
        config.ConnectionString = "Server=localhost;Database=unleasharp;Uid=unleasharp;Pwd=unleasharp;";
    })
    .WithOnQueryExceptionAction    ((query, ex) => Console.WriteLine($"Exception executing query:   {query.QueryRenderedString}\nException message:\n{ex.Message}"))
    .WithBeforeQueryExecutionAction((query    ) => Console.WriteLine($"Preparing query for execute: {query.Render()}"))
    .WithAfterQueryExecutionAction ((query    ) => Console.WriteLine($"Executed query:              {query.QueryRenderedString}"))
;

Using MySqlConnectionStringBuilder

ConnectorManager DBConnector = new ConnectorManager(
    new MySqlConnectionStringBuilder("Server=localhost;Database=unleasharp;Uid=unleasharp;Pwd=unleasharp;")
);

📝 Usage Examples

Sample Table Structure

using System.ComponentModel;
using Unleasharp.DB.Base.SchemaDefinition;

namespace Unleasharp.DB.MySQL.Sample;

[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 long? 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;
    }
}


public enum EnumExample 
{
    NONE,
    [Description("Y")]
    Y,
    [Description("NEGATIVE")]
    N
}

Sample Program

using System;
using System.Collections.Generic;
using Unleasharp.DB.MySQL;
using Unleasharp.DB.Base.QueryBuilding;

namespace Unleasharp.DB.MySQL.Sample;

internal class Program 
{
    static void Main(string[] args) 
    {
        // Initialize database connection
        ConnectorManager dbConnector = new ConnectorManager("Server=localhost;Database=unleasharp;Uid=unleasharp;Pwd=unleasharp;")
            .WithOnQueryExceptionAction(ex => Console.WriteLine(ex.Message))
        ;

        // Create table if needed
        Console.WriteLine(dbConnector.QueryBuilder().Build(Query => Query.Create<ExampleTable>()).Execute().DBQuery.QueryRenderedString);

        // Insert data
        dbConnector.QueryBuilder().Build(Query => { Query
            .From<ExampleTable>()
            .Value(new ExampleTable {
                MediumText = "Medium text example value",
                Enum       = EnumExample.N
            })
            .Values(new List<ExampleTable> {
                new ExampleTable {
                    Json            = @"{""sample_json_field"": ""sample_json_value""}",
                    Enum            = EnumExample.Y,
                    CustomFieldName = new byte[8] { 81,47,15,21,12,16,23,39 }
                },
                new ExampleTable {
                    Longtext = "Long text example value",
                    Enum     = EnumExample.N
                }
            })
            .Insert();
        }).Execute();
        
        // Select single row
        ExampleTable row = dbConnector.QueryBuilder().Build(Query => Query
            .From<example_table>()
            .OrderBy("id", OrderDirection.DESC)
            .Limit(1)
            .Select()
        ).FirstOrDefault<ExampleTable>();

        // Select multiple rows with different class naming
        List<example_table> rows = dbConnector.QueryBuilder().Build(Query => Query
            .From("example_table")
            .OrderBy("id", OrderDirection.DESC)
            .Select()
        ).ToList<example_table>();

        // Update a specific row using query Expressions
        dbConnector.QueryBuilder().Build(query => query
            .From <ExampleTable>()
            .Set  <ExampleTable>((row) => row.MediumText,      "Edited medium text")
            .Set  <ExampleTable>((row) => row.Longtext,        "Edited long text")
            .Set  <ExampleTable>((row) => row.Json,            @"{""json_field"": ""json_edited_value""}")
            .Set  <ExampleTable>((row) => row.CustomFieldName, new byte[8] { 12, 13, 14, 15, 12, 13, 14, 15 })
            .Set  <ExampleTable>((row) => row.Enum,            EnumExample.N)
            .Set  <ExampleTable>((row) => row.Varchar,         "Edited varchar")
            .Where<ExampleTable>((row) => row.Id,              row.Id)
            .Update()
        ).Execute();

        // Retrieve a row using query Expressions
        ExampleTable expressionRow = dbConnector.QueryBuilder().Build(query => query
            .Select <ExampleTable>(row => row.Id)
            .From   <ExampleTable>()
            .Where  <ExampleTable>(row => row.MediumText, "Edited medium text")
            .OrderBy<ExampleTable>(row => row.Id,         OrderDirection.DESC)
            .Limit(1)
        ).FirstOrDefault<ExampleTable>();
    }
}

Sample Query Rendering

// Complex query demonstration with subqueries
Query veryComplexQuery = Query.GetInstance()
    .Select("query_field")
    .Select($"COUNT({new FieldSelector("table_x", "table_y")})", true)
    .From("query_from")
    .Where("field", "value")
    .WhereIn(
        "field_list",
        Query.GetInstance()
            .Select("*", false)
            .From("subquery_table")
            .Where("subquery_field", true)
            .WhereIn(
                "subquery_in_field",
                Query.GetInstance()
                    .Select("subquery_subquery_in_field")
                    .From("subquery_subquery_in_table")
                    .Where("subquery_subquery_in_where", true)
            )
            .Limit(100)
    )
    .WhereIn("field_list", new List<dynamic> { null, 123, 456, "789" })
    .Join("another_table", new FieldSelector("table_x", "field_x"), new FieldSelector("table_y", "field_y"))
    .OrderBy(new OrderBy {
        Field     = new FieldSelector("order_field"),
        Direction = OrderDirection.DESC
    })
    .GroupBy("group_first")
    .GroupBy("group_second")
    .Limit(100);

// Render raw SQL query
Console.WriteLine(veryComplexQuery.Render());

// Render prepared statement query (with placeholders)
Console.WriteLine(veryComplexQuery.RenderPrepared());

📦 Dependencies

📋 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.


For more information about Unleasharp.DB.Base, visit: Unleasharp.DB.Base

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.7.0 108 9/11/2025
1.6.0 131 9/3/2025
1.5.5 123 9/1/2025
1.5.3 137 8/31/2025
1.5.2 146 8/30/2025
1.5.0 173 8/28/2025
1.4.1 174 8/28/2025
1.4.0 173 8/28/2025
1.3.1 187 8/26/2025
1.3.0 150 8/25/2025
1.2.0 58 8/22/2025
1.1.1 120 8/21/2025
1.1.0 125 8/20/2025
1.0.2 125 8/20/2025
1.0.1 126 8/20/2025
1.0.0 126 8/19/2025