Add project files.

This commit is contained in:
2023-10-27 19:00:41 +07:00
parent 54a23f5c2c
commit 3949c3c62a
27 changed files with 1238 additions and 0 deletions

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleTemplate.Repositories
{
internal interface IRepository
{
bool InitDB();
}
}

View File

@ -0,0 +1,33 @@
using ConsoleTemplate.Contexts;
using ConsoleTemplate.Services;
using MySqlConnector;
namespace ConsoleTemplate.Repositories
{
internal class MysqlRepository : IRepository
{
private IDBContext _dbContext;
private LogService _log;
public MysqlRepository(IDBContext dbContext, LogService logger)
{
_dbContext = dbContext;
_log = logger;
}
public bool InitDB()
{
using (MySqlConnection con = (MySqlConnection)_dbContext.GetWriteConn())
{
_log.Info("Init DB");
con.Open();
MySqlCommand cmd = con.CreateCommand();
cmd.CommandText = $"CREATE DATABASE IF NOT EXISTS `{Conf.DB_SCHEME}`";
cmd.ExecuteNonQuery();
return true;
}
}
}
}