using Dapper; using System; using System.Collections.Generic; using System.Data; using System.Data.SQLite; using System.Diagnostics; using System.Linq; namespace CryptoCalc { public class DBInteraction { public static void SaveData(ref T data) where T : DBClasses { if (data is null) { throw new ArgumentNullException(nameof(data)); } using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString(data.DBTableName)); cnn.Execute($"insert into {data.DBTableName} {data.DBSaveDataString}", data); Debug.WriteLine($"Saved {data.DBTableName} DB data"); } public class GenericDB where T : DBClasses { public IEnumerable LoadAllData(string tableName) { if (tableName is null) { throw new ArgumentNullException(nameof(tableName)); } using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString(tableName)); return _connection.Query($"select * from {tableName}", new DynamicParameters()); } } } }