41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
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<T>(T data) where T : DBClasses
|
|
{
|
|
if (data is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(data), "No data passed to SQL");
|
|
}
|
|
|
|
using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString(data.DBName));
|
|
cnn.Execute($"insert into {data.DBTableName} {data.DBSaveDataString}", data);
|
|
Debug.WriteLine($"Saved {data.DBTableName} DB data");
|
|
}
|
|
|
|
|
|
public class GenericDB<T> where T : DBClasses
|
|
{
|
|
public IEnumerable<T> QueryData(T data, string query)
|
|
{
|
|
if (data is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(data), "DBclass is null");
|
|
}
|
|
|
|
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString(data.DBName));
|
|
return _connection.Query<T>($"{query}", new DynamicParameters());
|
|
}
|
|
}
|
|
}
|
|
}
|