Added MariaDB -> SQLite conversion utility.

This commit is contained in:
flash 2025-04-28 19:22:31 +00:00
commit eae379e933
Signed by: flash
GPG key ID: 2C9C2C574D47FE3E
6 changed files with 82 additions and 18 deletions
SharpChat.SQLite

View file

@ -5,8 +5,10 @@ using NativeSQLiteConnection = System.Data.SQLite.SQLiteConnection;
namespace SharpChat.SQLite;
public class SQLiteConnection(NativeSQLiteConnection conn) : IDisposable {
public NativeSQLiteConnection Connection { get; } = conn;
public async Task<int> RunCommand(string command, params SQLiteParameter[] parameters) {
using SQLiteCommand cmd = conn.CreateCommand();
using SQLiteCommand cmd = Connection.CreateCommand();
if(parameters?.Length > 0)
cmd.Parameters.AddRange(parameters);
cmd.CommandText = command;
@ -14,7 +16,7 @@ public class SQLiteConnection(NativeSQLiteConnection conn) : IDisposable {
}
public async Task<DbDataReader?> RunQuery(string command, params SQLiteParameter[] parameters) {
using SQLiteCommand cmd = conn.CreateCommand();
using SQLiteCommand cmd = Connection.CreateCommand();
if(parameters?.Length > 0)
cmd.Parameters.AddRange(parameters);
cmd.CommandText = command;
@ -23,7 +25,7 @@ public class SQLiteConnection(NativeSQLiteConnection conn) : IDisposable {
public async Task<T> RunQueryValue<T>(string command, params SQLiteParameter[] parameters)
where T : struct {
using SQLiteCommand cmd = conn.CreateCommand();
using SQLiteCommand cmd = Connection.CreateCommand();
if(parameters?.Length > 0)
cmd.Parameters.AddRange(parameters);
cmd.CommandText = command;
@ -50,6 +52,6 @@ public class SQLiteConnection(NativeSQLiteConnection conn) : IDisposable {
disposed = true;
RunCommand("VACUUM").Wait();
conn.Dispose();
Connection.Dispose();
}
}