34 lines
864 B
C#
34 lines
864 B
C#
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;
|
|
}
|
|
}
|
|
}
|
|
}
|