You've already forked CsharpTemplate
Add project files.
This commit is contained in:
13
ConsoleTemplate/Repositories/IRepository.cs
Normal file
13
ConsoleTemplate/Repositories/IRepository.cs
Normal 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();
|
||||
}
|
||||
}
|
33
ConsoleTemplate/Repositories/MysqlRepository.cs
Normal file
33
ConsoleTemplate/Repositories/MysqlRepository.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user