Nexd.MySQL 1.0.2

dotnet add package Nexd.MySQL --version 1.0.2
NuGet\Install-Package Nexd.MySQL -Version 1.0.2
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="Nexd.MySQL" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Nexd.MySQL --version 1.0.2
#r "nuget: Nexd.MySQL, 1.0.2"
#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.
// Install Nexd.MySQL as a Cake Addin
#addin nuget:?package=Nexd.MySQL&version=1.0.2

// Install Nexd.MySQL as a Cake Tool
#tool nuget:?package=Nexd.MySQL&version=1.0.2

C# Sync & Async MySQL (MySqlConnector library) Wrapper

Installation

Available on NuGet NuGet version (Nexd.Reflection)

dotnet add package Nexd.MySQL --version 1.0.2

Initialization

// import using
using Nexd.MySQL;

MySqlDb MySql = new MySqlDb("localhost", "root", "password", "database");

ExecuteQuery & ExecuteNonQuery usage (unsafe)

These functions are not safe in the context of SQL injection. Make sure to escape your values correctly before executing. (MySqlHelper.EscapeString(value);)

MySql.ExecuteQuery($"SELECT * FROM `Players` WHERE Name = '{name}';", name); make sure that the name is escaped.

MySql.ExecuteNonQuery("DELETE * FROM `Players`;");

Where condition

// WITH WRAPPER CLASSES
MySqlQueryCondition conditions = new MySqlQueryCondition()
    .Add("ID", ">", "1002")
    .Add("ID", "<=", "1008");

MySqlQueryResult result = MySql.Table("players").Where(conditions).Select();
for(int i = 0; i < result.Rows; i++)
{
    Console.WriteLine($"{result.Get<int>(i, "ID")} {result.Get<string>(i, "Name")} {result.Get<string>(i, "Identifier")}");
}

// WITHOUT
MySqlQueryResult result = MySql.Table("players").Where("ID > 1002 AND ID <= 1008").Select();
for(int i = 0; i < result.Rows; i++)
{
    Console.WriteLine($"{result.Get<int>(i, "ID")} {result.Get<string>(i, "Name")} {result.Get<string>(i, "Identifier")}");
}

Insert Query

MySqlQueryValue values = new MySqlQueryValue()
    .Add("Name", "Player Name #1") // DB column is 'Name', insert data 'Player Name #1'
    .Add("Identifier", "uniqueidentifier"); // DB column is 'Identifier', insert data 'uniqueidentifier'

// assume there is a table named 'players'
MySql.Table("players").Insert(values);

Update Query

MySqlQueryValue values = new MySqlQueryValue()
    .Add("Name", "Player Name #2");

// with wrapper classes
int rowsAffected = MySql.Table("players").Where(MySqlQueryCondition.New("Identifier", "=", "uniqueidentifier")).Update(values);

// without
int rowsAffected = MySql.Table("players").Where("Identifier = 'uniqueidentifier'").Update(values);
int rowsAffected = MySql.Table("players").Where("Identifier = 'uniqueidentifier' AND ID > 0").Update(values); // random example that shows you can define your where statement just as you like

Select Query

// with wrapper classes
MySqlQueryResult result = MySql.Table("players").Where(MySqlQueryCondition.New("Identifier", "=", "uniqueidentifier")).Select();

// without
MySqlQueryResult result = MySql.Table("players").Where("Identifier = 'uniqueidentifier'").Select(); // you can specify the fields (columns) you want to select, also LIMIT the amount of results by passing them to the .Select() as parameters

// then
int playerId = result.Get<int>(0, "ID"); // 0 is the row, "ID" is the column name in the results
DateTime registeredAt = result.Get<DateTime>(0, "CreationDate"); // 0 is the row, "CreationDate" is the column name in the results

Delete Query

// with wrapper classes
int rowsAffected = MySql.Table("players").Where(MySqlQueryCondition.New("Identifier", "=", "uniqueidentifier")).Delete();

// without
int rowsAffected = MySql.Table("players").Where("Identifier = 'uniqueidentifier'").Delete();

Async

Note: that every method has its Async version implemented

Documentation is currently unavailable, but its self explanatory and has the same syntax with the sync version, just with Async method names.

TODO / Missing

  • Joins
  • Subqueries
  • Group by?
  • Order by?
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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 was computed.  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. 
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.0.2 1,312 12/3/2023
1.0.1 596 11/5/2023
1.0.0 129 11/4/2023