DATABASE WOOOOOOOOOOOOOOOOOOO!
This commit is contained in:
40
Services/DatabaseService.cs
Normal file
40
Services/DatabaseService.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Linq.Expressions;
|
||||
using Microsoft.Data.Sqlite;
|
||||
|
||||
namespace Reactor.Services
|
||||
{
|
||||
public static class DatabaseService
|
||||
{
|
||||
private static string _connectionString = "Data Source=reactor.db";
|
||||
|
||||
public static async Task InitializeAsync()
|
||||
{
|
||||
using var connection = new SqliteConnection(_connectionString);
|
||||
await connection.OpenAsync();
|
||||
|
||||
//ReactionMessages Table
|
||||
var cmd1 = connection.CreateCommand();
|
||||
cmd1.CommandText =
|
||||
"CREATE TABLE IF NOT EXISTS ReactionMessages (" +
|
||||
"Id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||
"PlanetId INTEGER NOT NULL, " +
|
||||
"ChannelId INTEGER NOT NULL, " +
|
||||
"MessageId INTEGER NOT NULL UNIQUE, " +
|
||||
"DeleteDelaySeconds INTEGER NOT NULL DEFAULT 5" +
|
||||
")";
|
||||
await cmd1.ExecuteNonQueryAsync();
|
||||
|
||||
//ReactionRoles table
|
||||
var cmd2 = connection.CreateCommand();
|
||||
cmd2.CommandText =
|
||||
"CREATE TABLE IF NOT EXISTS ReactionRoles (" +
|
||||
"Id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||
"ReactionMessageId INTEGER NOT NULL, " +
|
||||
"Emoji TEXT NOT NULL, " +
|
||||
"RoleId INTEGER NOT NULL, " +
|
||||
"FOREIGN KEY (ReactionMessageId) REFERENCES ReactionMessages(Id) ON DELETE CASCADE" +
|
||||
")";
|
||||
await cmd2.ExecuteNonQueryAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user