using Microsoft.EntityFrameworkCore; using OptixServe.Api.Configuration; using OptixServe.Core.Data; namespace OptixServe.Api.Utilites; public static class DatabaseHelper { public static string BuildConnectionString(DatabaseSettings dbSettings) { return dbSettings.Type switch { DatabaseType.Sqlite => $"Data Source={dbSettings.Host ?? "optixserve.db"}", DatabaseType.MySQL => throw new NotSupportedException("MySQL connection is not yet implemented"), _ => throw new NotSupportedException($"Database type {dbSettings.Type} is not supported") }; } public static void ConfigureDbContext(DbContextOptionsBuilder options, DatabaseSettings dbSettings) { if (dbSettings?.Type == DatabaseType.Sqlite) { var dbPath = dbSettings.Host ?? "optixserve.db"; var connectionString = $"Data Source={dbPath}"; options.UseSqlite(connectionString, b => b.MigrationsAssembly("OptixServe.Api")); } else { throw new NotImplementedException("Only SQLite database is currently supported"); } } }