CsharpTemplate/ConsoleTemplate/Repositories/MysqlRepository.cs

34 lines
864 B
C#
Raw Permalink Normal View History

2023-10-27 19:00:41 +07:00
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;
}
}
}
}