This commit is contained in:
flash 2025-04-29 22:14:51 +00:00
parent a487a8dadf
commit 67202d27f7
Signed by: flash
GPG key ID: 2C9C2C574D47FE3E
3 changed files with 7 additions and 4 deletions
SharpChat.MariaDB
SharpChat.SQLite
SharpChat

View file

@ -8,6 +8,7 @@ public class MariaDBConnection(MySqlConnection conn) : IDisposable {
public async Task<int> RunCommand(string command, params MySqlParameter[] parameters) {
using MySqlCommand cmd = Connection.CreateCommand();
cmd.Parameters.Clear();
if(parameters?.Length > 0)
cmd.Parameters.AddRange(parameters);
cmd.CommandText = command;
@ -16,6 +17,7 @@ public class MariaDBConnection(MySqlConnection conn) : IDisposable {
public async Task<MySqlDataReader?> RunQuery(string command, params MySqlParameter[] parameters) {
using MySqlCommand cmd = Connection.CreateCommand();
cmd.Parameters.Clear();
if(parameters?.Length > 0)
cmd.Parameters.AddRange(parameters);
cmd.CommandText = command;
@ -25,6 +27,7 @@ public class MariaDBConnection(MySqlConnection conn) : IDisposable {
public async Task<T> RunQueryValue<T>(string command, params MySqlParameter[] parameters)
where T : struct {
using MySqlCommand cmd = Connection.CreateCommand();
cmd.Parameters.Clear();
if(parameters?.Length > 0)
cmd.Parameters.AddRange(parameters);
cmd.CommandText = command;

View file

@ -9,6 +9,7 @@ public class SQLiteConnection(NativeSQLiteConnection conn) : IDisposable {
public async Task<int> RunCommand(string command, params SQLiteParameter[] parameters) {
using SQLiteCommand cmd = Connection.CreateCommand();
cmd.Parameters.Clear();
if(parameters?.Length > 0)
cmd.Parameters.AddRange(parameters);
cmd.CommandText = command;
@ -17,6 +18,7 @@ public class SQLiteConnection(NativeSQLiteConnection conn) : IDisposable {
public async Task<DbDataReader?> RunQuery(string command, params SQLiteParameter[] parameters) {
using SQLiteCommand cmd = Connection.CreateCommand();
cmd.Parameters.Clear();
if(parameters?.Length > 0)
cmd.Parameters.AddRange(parameters);
cmd.CommandText = command;
@ -26,6 +28,7 @@ public class SQLiteConnection(NativeSQLiteConnection conn) : IDisposable {
public async Task<T> RunQueryValue<T>(string command, params SQLiteParameter[] parameters)
where T : struct {
using SQLiteCommand cmd = Connection.CreateCommand();
cmd.Parameters.Clear();
if(parameters?.Length > 0)
cmd.Parameters.AddRange(parameters);
cmd.CommandText = command;

View file

@ -1,12 +1,9 @@
using Microsoft.Extensions.Logging;
using MySqlConnector;
using SharpChat;
using SharpChat.Configuration;
using SharpChat.Flashii;
using SharpChat.MariaDB;
using SharpChat.SQLite;
using System.Data.SQLite;
using System.Reflection.PortableExecutable;
using System.Text;
using ZLogger;
using ZLogger.Providers;
@ -157,7 +154,7 @@ if(cts.IsCancellationRequested) return;
if(args.Contains("--migrate-storage") || args.Contains("--convert-db")) {
MariaDBStorage mariadb = new(logFactory.CreateLogger("mariadb"), MariaDBStorage.BuildConnectionString(config.ScopeTo("mariadb")));
using SQLiteStorage sqlite = new(logFactory.CreateLogger("sqlite"), SQLiteStorage.BuildConnectionString(config.ScopeTo("sqlite"), false));
await new StorageMigrator(logFactory.CreateLogger("migrate"), mariadb, sqlite).Migrate(cts.Token);
await new StorageMigrator(logFactory.CreateLogger("migrate"), sqlite, mariadb).Migrate(cts.Token);
return;
}