first commit

This commit is contained in:
JacobTech 2024-02-27 17:42:25 -05:00
commit 4c261d035b
5 changed files with 106 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
.idea/
discord.xml

16
MySQL_Manager.sln Normal file
View File

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MySQL_Manager", "MySQL_Manager\MySQL_Manager.csproj", "{0A6AA01B-91AE-4BBB-90E5-C15F70197601}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0A6AA01B-91AE-4BBB-90E5-C15F70197601}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A6AA01B-91AE-4BBB-90E5-C15F70197601}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A6AA01B-91AE-4BBB-90E5-C15F70197601}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A6AA01B-91AE-4BBB-90E5-C15F70197601}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

53
MySQL_Manager/Database.cs Normal file
View File

@ -0,0 +1,53 @@
using MySqlConnector;
namespace MySQL_Manager;
public class Database
{
private string conection;
public Database(string ConnectionString)
{
conection = ConnectionString;
}
public void ExecuteNonQuery(string command)
{
try
{
MySqlConnection conn = new MySqlConnection(conection);
conn.Open();
MySqlCommand cmd = new MySqlCommand(command, conn);
_ = cmd.ExecuteNonQuery();
conn.Close();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
public TReturn Read<TReturn>(string command)
{
try
{
MySqlConnection conn = new MySqlConnection(conection);
conn.Open();
MySqlCommand cmd = new MySqlCommand(command, conn);
object? temp = cmd.ExecuteScalar();
if (temp is DBNull || temp is null)
{
return default!;
}
if (typeof(TReturn).IsEnum) return (TReturn?)Enum.Parse(typeof(TReturn), temp.ToString()!)!;
if (typeof(TReturn).IsNullableEnum()) return (TReturn?)Enum.Parse(Nullable.GetUnderlyingType(typeof(TReturn))!, temp.ToString()!)!;
return (TReturn?)temp!;
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}

10
MySQL_Manager/EXT.cs Normal file
View File

@ -0,0 +1,10 @@
namespace MySQL_Manager;
internal static class EXT
{
internal static bool IsNullableEnum(this Type t)
{
Type u = Nullable.GetUnderlyingType(t)!;
return (u != null) && u.IsEnum;
}
}

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Title>MySQL Manager</Title>
<Description>A Database class to handle database interactions in MySQL for school Projects</Description>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MySqlConnector" Version="2.3.5" />
</ItemGroup>
<Target Name="CustomActionsAfterPublish" AfterTargets="Pack">
<Message Text="Actions AfterPublish: $(PackageId).$(PackageVersion).nupkg" Importance="high" />
<Exec Command="nuget push -Source https://nuget.jacobtech.com/v3/index.json bin/Release/$(PackageId).$(PackageVersion).nupkg" />
</Target>
</Project>