47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using System;
|
|
using System.Data;
|
|
using Microsoft.Data.Sqlite;
|
|
using Microsoft.Extensions.Configuration;
|
|
using NLog;
|
|
|
|
namespace ChaosBot.Controllers
|
|
{
|
|
public class Database
|
|
{
|
|
private SqliteConnection _conn = new SqliteConnection($"Data Source={System.IO.Directory.GetCurrentDirectory()}{Program.Cfg.GetValue<string>("Bot:Database")}");
|
|
private static Logger _logger = Program._logger;
|
|
|
|
public DataTable RawQuery(string query)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
|
|
try
|
|
{
|
|
using (_conn)
|
|
{
|
|
_conn.Open();
|
|
|
|
SqliteCommand cmd = _conn.CreateCommand();
|
|
cmd.CommandText = query;
|
|
SqliteDataReader executeReader = cmd.ExecuteReader(CommandBehavior.SingleResult);
|
|
|
|
dt.Load(executeReader);
|
|
|
|
_conn.Close();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Fatal($"Controllers.Database.RawQuery: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
|
}
|
|
|
|
return dt;
|
|
}
|
|
}
|
|
|
|
public class Raffle
|
|
{
|
|
private int _id;
|
|
private ulong userId;
|
|
}
|
|
} |