Ziedden.MySql 1.0.0

dotnet add package Ziedden.MySql --version 1.0.0
                    
NuGet\Install-Package Ziedden.MySql -Version 1.0.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="Ziedden.MySql" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ziedden.MySql" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Ziedden.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 Ziedden.MySql --version 1.0.0
                    
#r "nuget: Ziedden.MySql, 1.0.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 Ziedden.MySql@1.0.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=Ziedden.MySql&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Ziedden.MySql&version=1.0.0
                    
Install as a Cake Tool

Ziedden.MySql für .Net

Beschreibung

Mit diesen Parser ist es möglich Klassen direkt in/aus die MySql Datenbank zu speicher und zu laden.

Benötigt

  • MySql Connector/NET
  • Newtonsoft.Json

Infos

Arbieten mit ID's

Ich rate jedem dazu mit den ID System zu arbeiten. Es ist deutlich Verwechslungssicherer.

MySql Speicherung

Alles Daten die eingespeichert werden, werden im JSON vormat abgespeichert. Wenn die Datenbank noch anders verwendet wird z.B. mit PHP für einen Webiste muss dieses beachtet werden.

HowTo

Connection

Als erstes muss die Connection erstellt werden.

  Ziedden.Mysql.Parser p = new Ziedden.Mysql.Parser("Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;");

oder

  Ziedden.Mysql.Parser p = new Ziedden.Mysql.Parser("myServerAddress","myUsername","myPassword","myDataBase");

Attribute

Damit der Parser auch die Objecte erkennt müssen Attribute gesetzt werden z.B.:

  public class User
  {
        [Mysql.MysqlData]
        public int ID;

        [Mysql.MysqlData]
        public string Username;

        [Mysql.MysqlData]
        public string Password;

        [Mysql.MysqlData]
        public string Email;
  }

Die ID wird immer angelegt. Diese wird als fortlaufende Nummer verwendet.

Insert

Der Insert Befehl ist um einen Eintrag zu tätigen. Ist keine Tabelle vorhanden so wird eine erstellt. Der MySql Tabellen Name wird vom Klassennamen abgeleitet. Ist der Rückgabewert -1 ist ein Fehler unterlaufen.

Ziedden.Mysql.Parser connection = new Ziedden.Mysql.Parser(ConnectionString);

//Init Klass
User newUser = new User();
newUser.Username = "Bsp";
newUser.Password = "Strong";
newUser.Email = "Bsp@example.com"

int inserID = connection.Insert(newUser);
Console.WriteLine("Eintrage wurde mit der ID {0} erstellt",inserID);

Delete

Der Befehl Delete löscht einen Eintrag aus der Tabelle. Hier gibt es zwei möglichkeiten.

NR 1

In diesen Fall wird mit der ID gearbeitet.

Ziedden.Mysql.Parser connection = new Ziedden.Mysql.Parser(ConnectionString);

int userID = 5;
connection.Delete(userID);

NR 2

In diesen Fall wird ohne ID gearbeitet.

Ziedden.Mysql.Parser connection = new Ziedden.Mysql.Parser(ConnectionString);

string Username = "Bsp";
connection.Delte(typeof(User),new Ziedden.Mysql.Parser.Where[]  {new Ziedden.Mysql.Parser.Where("Username",Username)});

FindWhere

Mit FindWhere kann man einen Eintrag mit dem passenden Daten suchen. Alles Einträge mit den passenden Daten werden als Array ausgegeben.

Ziedden.Mysql.Parser connection = new Ziedden.Mysql.Parser(ConnectionString);

string Username = "Bsp";
string Email = "Bsp@example.com";
User[] foundUser = connection.FindWhere<User>(new Ziedden.Mysql.Parser.Where[]  {new Ziedden.Mysql.Parser.Where("Username",Username),new Ziedden.Mysql.Parser.Where("Email",Email)});

FindByID

FindByID kann nur verwendet werden wenn die ID in der Klasse vorhanden ist (Siehe Bsp User).

Ziedden.Mysql.Parser connection = new Ziedden.Mysql.Parser(ConnectionString);

int userID = 5;
User foundUser = connection.FindByID<User>(userID);

Update

Mit dem Befehl Update kann man Einträge bearbieten. Hier gibt es auch wieder zwei Fälle. Die Funktion gibt einen bool zurück ob die Aktion erfolgreich war oder nicht.

NR 1

In diesen Fall wird mit der ID gearbeitet.

Ziedden.Mysql.Parser connection = new Ziedden.Mysql.Parser(ConnectionString);

int userID = 5;
User foundUser = connection.FindByID(userID);

foundUser.Email = "newBsp@example.com";

connection.Update(foundUser);

NR 2

In diesen Fall wird ohne ID gearbeitet.

Ziedden.Mysql.Parser connection = new Ziedden.Mysql.Parser(ConnectionString);

string Username = "Bsp";
User[] foundUsers = connection.FindWhere(new Ziedden.Mysql.Parser.Where[]  {new Ziedden.Mysql.Parser.Where("Username",Username)});

if(foundUsers.Count > 0)
{
  User[0].Email = "newBsp@example.com";
  connection.Update(User[0].Email,"Username",Username);
}

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.  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. 
.NET Core netcoreapp3.1 is compatible. 
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.0 279 10/21/2022

First Release