transactions
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using back.Options;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace back.ServicesExtensions;
|
||||
|
||||
@@ -59,6 +60,14 @@ public static partial class DbContextOptionsBuilderExtensions
|
||||
switch (provider)
|
||||
{
|
||||
case DatabaseProvider.Sqlite:
|
||||
var match = SQLiteRegex().Match(config.ConnectionString ?? string.Empty);
|
||||
if (match.Success)
|
||||
{
|
||||
string? folder = null;
|
||||
string path = match.Groups[1].Value.Replace("\\", "/");
|
||||
folder = path.Contains('/') ? path[..path.IndexOf('/')] : path;
|
||||
Directory.CreateDirectory(folder);
|
||||
}
|
||||
options.UseSqlite(config.ConnectionString);
|
||||
break;
|
||||
case DatabaseProvider.InMemory:
|
||||
@@ -77,4 +86,7 @@ public static partial class DbContextOptionsBuilderExtensions
|
||||
throw new InvalidOperationException($"Unsupported database provider: {config.Provider}");
|
||||
}
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"Data Source=([^;]+)")]
|
||||
private static partial Regex SQLiteRegex();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user