UskokMySQL 1.4.0

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

// Install UskokMySQL as a Cake Tool
#tool nuget:?package=UskokMySQL&version=1.4.0

Uskok-MYSQL

Uskok-MYSQL is a library that I used to do some private work so I thought why not upload it to github. It uses .NET Reflections to achieve a bit painless mysql experience in .NET. Also it creates async mysql connection pool so that creating a new connection for each request it not required. Amount of open connection at one time is customizable for each database.

Examples

Connecting to a database

//This line connects to a database in another thread and opens 5 concurrent connections
Database Database = new("ConnectionString", 5);

Creating a table

Database Database = new("ConnectionString", 5);
class TestTableColumn
{
    public int ID;
    public string Name;
}
//This creates a table and executes a mysql query to create the table if it does not exist.
//The create request 'CREATE TABLE IF NOT EXISTS `Table_Name`(ID INT, Name TEXT);'

DatabaseTable<TestTableColumn> Table = new("Table_Name", Database);
//Note: the operation is concurrent so the table might not be created in the database 
//even after this line so use Table.Created variable if you want to check 

Column Attributes

PrimaryKey

Used for marking the primary key of the table(please use only one per table):

class Person
{
    [PrimaryKey]
    public int SocialNumber;
    public string Name;
}

Results in:

CREATE TABLE IF NOT EXIST `Table_Name` (SocialNumber INT PRIMARY KEY, Name TEXT);'

AutoIncrement

Used for marking a auto increment column When inserting this column will autmaticlly be assigned to null

class Person
{
    [AutoIncrement]
    public int SocialNumber;
    public string Name;
}

Results in:

CREATE TABLE IF NOT EXIST `Table_Name` (SocialNumber INT AUTO_INCREMENT, Name TEXT);

NotNull

Used for marking a column that is not null

class Person
{
    public int SocialNumber;
    [NotNull]
    public string Name;
}

Results in:

CREATE TABLE IF NOT EXIST `Table_Name` (SocialNumber INT, Name TEXT NOT NULL);

ColumnIgnore

Used for marking a column that is to be ignored

class Person
{
    public int SocialNumber;
    [ColumnIgnore]
    public string Name;
}

Results in:

CREATE TABLE IF NOT EXIST `Table_Name` (SocialNumber INT);

MaxLength

Used for specifying the max length in a string(converts it to varchar)

class Person
{
    public int SocialNumber;
    [MaxLength(30)]
    public string Name;
}

Results in:

CREATE TABLE IF NOT EXIST `Table_Name` (SocialNumber INT, Name VARCHAR(30));

ColumnName

Used for setting a custom name to a column

class Person
{
    public int SocialNumber;
    [ColumnName("personName")]
    public string Name;
}

Results in:

CREATE TABLE IF NOT EXIST `Table_Name` (SocialNumber INT, personName TEXT);

Writing queries

Inserting & Replacing

class Person
{
    [PrimaryKey]
    public int SocialNumber;
    public string Name;
}
DatabaseTable<Person> Table = new("Table_Name", Database);
Person p1 = new () { SocialNumber = 0, Name = "John Doe" };
Person p2 = new () { SocialNumber = 1, Name = "John Doe" };
...
await Table.Insert(p1, p2, ...);

Now renaming(replacing) them

p1.Name = "New John";
p2.Name = "New Jane";
...
await Table.Replace(p1, p2, ...);

Inserting and getting inserted ids

class Person
{
    [PrimaryKey, AutoIncrement]
    public long SocialNumber;
    public string Name;
}
DatabaseTable<Person> Table = new("Table_Name", Database);
Person p1 = new (){ Name = "John Doe" };
Person p2 = new (){ Name = "Jane Doe" };
long[] ids = await Table.InsertAndReturnKeys<long>(p1, p2);
// Table content
// SocialNumber  |  Name
//      0        |  "John Doe"
//      1        |  "John Doe"
// ids Array
// Index | Value
//   0   |   0
//   1   |   1

Where query

Use Table.All for all where queries, example:

All(string? whereCommand = null, string? alias = null, string? selector = null, bool debugPrint = false)<br> An example of SELECT * FROM table_name WHERE name='John'

class Person
{
    [PrimaryKey, AutoIncrement]
    public long SocialNumber;
    public string Name;
}
DatabaseTable<Person> Table = new("Table_Name", Database);
List<Person> peopleOfNameJohn = await Table.All("name='John'");
Now explaining the parameters

selector(default: *) - SELECT selector FROM<br> alias - if used it adds a string after the FROM: SELECT selector FROM Table_Name as alias<br> whereCommand - used

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.4.0 186 4/1/2023
1.3.0 196 3/28/2023
1.2.0 176 3/27/2023
1.1.0 203 3/19/2023
1.0.0 199 3/19/2023

Fixed a bug where if you had a ignored column before a primary key column it would get the wrong column index therefore when getting the column by key the wrong column will be picked.