Added MariaDB -> SQLite conversion utility.
This commit is contained in:
parent
c537df792e
commit
eae379e933
6 changed files with 82 additions and 18 deletions
SharpChat.SQLite
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue