Removed CLI project, added database migrations, added SQLHelper

This commit is contained in:
2025-06-06 00:29:38 +02:00
parent 89545b0d71
commit ad599433bf
10 changed files with 152 additions and 555 deletions

View File

@@ -3,6 +3,7 @@ using System.Data.Common;
using OllamaSharp;
using Microsoft.IdentityModel.Tokens;
using Server.Exceptions;
using Server.Migrations;
namespace Server;
@@ -29,8 +30,11 @@ public class SearchdomainManager
client = new(new Uri(ollamaURL));
connection = new MySqlConnection(connectionString);
connection.Open();
DatabaseMigrations.Migrate(new SQLHelper(connection));
}
public Searchdomain GetSearchdomain(string searchdomain)
{
if (searchdomains.TryGetValue(searchdomain, out Searchdomain? value))
@@ -40,7 +44,8 @@ public class SearchdomainManager
try
{
return SetSearchdomain(searchdomain, new Searchdomain(searchdomain, connectionString, client));
} catch (MySqlException)
}
catch (MySqlException)
{
_logger.LogError("Unable to find the searchdomain {searchdomain}", searchdomain);
throw new Exception($"Unable to find the searchdomain {searchdomain}");
@@ -105,6 +110,18 @@ public class SearchdomainManager
return command.ExecuteReader();
}
public void ExecuteSQLNonQuery(string query, Dictionary<string, dynamic> parameters)
{
using MySqlCommand command = connection.CreateCommand();
command.CommandText = query;
foreach (KeyValuePair<string, dynamic> parameter in parameters)
{
command.Parameters.AddWithValue($"@{parameter.Key}", parameter.Value);
}
command.ExecuteNonQuery();
}
public int ExecuteSQLCommandGetInsertedID(string query, Dictionary<string, dynamic> parameters)
{
using MySqlCommand command = connection.CreateCommand();