mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Tidy up context creation
This commit is contained in:
parent
5a684f926f
commit
129cca0704
@ -22,14 +22,29 @@ namespace osu.Game.Database
|
|||||||
public DbSet<RulesetInfo> RulesetInfo { get; set; }
|
public DbSet<RulesetInfo> RulesetInfo { get; set; }
|
||||||
private readonly string connectionString;
|
private readonly string connectionString;
|
||||||
|
|
||||||
public OsuDbContext()
|
static OsuDbContext()
|
||||||
{
|
{
|
||||||
connectionString = "DataSource=:memory:";
|
// required to initialise native SQLite libraries on some platforms.
|
||||||
|
SQLitePCL.Batteries_V2.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OsuDbContext(string connectionString)
|
/// <summary>
|
||||||
|
/// Create a new OsuDbContext instance.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connectionString">A valid SQLite connection string. If not provided, an in-memory instance will be created.</param>
|
||||||
|
public OsuDbContext(string connectionString = "DataSource=:memory:")
|
||||||
{
|
{
|
||||||
this.connectionString = connectionString;
|
this.connectionString = connectionString;
|
||||||
|
|
||||||
|
Database.SetCommandTimeout(new TimeSpan(TimeSpan.TicksPerSecond * 10));
|
||||||
|
|
||||||
|
var connection = Database.GetDbConnection();
|
||||||
|
connection.Open();
|
||||||
|
using (var cmd = connection.CreateCommand())
|
||||||
|
{
|
||||||
|
cmd.CommandText = "PRAGMA journal_mode=WAL;";
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
@ -81,21 +81,7 @@ namespace osu.Game
|
|||||||
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) =>
|
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) =>
|
||||||
dependencies = new DependencyContainer(base.CreateLocalDependencies(parent));
|
dependencies = new DependencyContainer(base.CreateLocalDependencies(parent));
|
||||||
|
|
||||||
private OsuDbContext createDbContext()
|
private OsuDbContext createDbContext() => new OsuDbContext(Host.Storage.GetDatabaseConnectionString(@"client"));
|
||||||
{
|
|
||||||
SQLitePCL.Batteries.Init();
|
|
||||||
var connectionString = Host.Storage.GetDatabaseConnectionString(@"client");
|
|
||||||
var context = new OsuDbContext(connectionString);
|
|
||||||
var connection = context.Database.GetDbConnection();
|
|
||||||
connection.Open();
|
|
||||||
using (var command = connection.CreateCommand())
|
|
||||||
{
|
|
||||||
command.CommandText = "PRAGMA journal_mode=WAL;";
|
|
||||||
command.ExecuteNonQuery();
|
|
||||||
}
|
|
||||||
context.Database.SetCommandTimeout(new TimeSpan(TimeSpan.TicksPerSecond * 10));
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
|
Loading…
Reference in New Issue
Block a user