Skip to content

Commit

Permalink
Format file, remove outcommented code.
Browse files Browse the repository at this point in the history
  • Loading branch information
expeehaa committed Jul 3, 2020
1 parent ceb3721 commit 24d4dea
Showing 1 changed file with 32 additions and 49 deletions.
81 changes: 32 additions & 49 deletions src/MitternachtBot/Services/DbService.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,36 @@
using Microsoft.EntityFrameworkCore;
using Mitternacht.Services.Database;

namespace Mitternacht.Services
{
public class DbService
{
private readonly DbContextOptions _options;

public DbService(IBotCredentials creds)
{
var optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder.UseSqlite(creds.DbConnectionString);
_options = optionsBuilder.Options;
//switch (_creds.Db.Type.ToUpperInvariant())
//{
// case "SQLITE":
// dbType = typeof(NadekoSqliteContext);
// break;
// //case "SQLSERVER":
// // dbType = typeof(NadekoSqlServerContext);
// // break;
// default:
// break;

//}
}

public NadekoContext GetDbContext()
{
var context = new NadekoContext(_options);
context.Database.SetCommandTimeout(60);
context.Database.Migrate();
context.EnsureSeedData();

//set important sqlite stuffs
var conn = context.Database.GetDbConnection();
conn.Open();

context.Database.ExecuteSqlRaw("PRAGMA journal_mode=WAL");
using (var com = conn.CreateCommand())
{
com.CommandText = "PRAGMA journal_mode=WAL; PRAGMA synchronous=OFF";
com.ExecuteNonQuery();
}

return context;
}

public IUnitOfWork UnitOfWork =>
new UnitOfWork(GetDbContext());
}
namespace Mitternacht.Services {
public class DbService {
private readonly DbContextOptions _options;

public DbService(IBotCredentials creds) {
var optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder.UseSqlite(creds.DbConnectionString);
_options = optionsBuilder.Options;
}

public NadekoContext GetDbContext() {
var context = new NadekoContext(_options);
context.Database.SetCommandTimeout(60);
context.Database.Migrate();
context.EnsureSeedData();

//set important sqlite stuffs
var conn = context.Database.GetDbConnection();
conn.Open();

context.Database.ExecuteSqlRaw("PRAGMA journal_mode=WAL");
using(var com = conn.CreateCommand()) {
com.CommandText = "PRAGMA journal_mode=WAL; PRAGMA synchronous=OFF";
com.ExecuteNonQuery();
}

return context;
}

public IUnitOfWork UnitOfWork =>
new UnitOfWork(GetDbContext());
}
}

0 comments on commit 24d4dea

Please sign in to comment.