adding Database
This commit is contained in:
parent
73b3c25c6f
commit
d383bd43d4
@ -19,6 +19,9 @@
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="ChaosBotSQL.db">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -1,8 +1,42 @@
|
||||
namespace ChaosBot.Controllers
|
||||
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
|
||||
|
||||
@ -4,6 +4,7 @@ using System.Text;
|
||||
using Discord.Commands;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using ChaosBot.Controllers;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NLog;
|
||||
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
{
|
||||
"Bot": {
|
||||
"Name": "ChaosBot",
|
||||
"Version": "1.0"
|
||||
"Version": "1.0",
|
||||
"Database": "ChaosBotSQL.db"
|
||||
},
|
||||
"Discord": {
|
||||
"Token": "NzE3ODM3Njg5Mzk0ODIzMjYy.XtgIew.JWUjvMDSzQT_a36D98CTrtb5lfI",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user