MireaBackend/Endpoint/Configuration/Model/GeneralSettings/DbSettings.cs

33 lines
1006 B
C#
Raw Normal View History

2024-06-01 10:59:23 +03:00
using Mirea.Api.DataAccess.Persistence.Common;
2024-10-07 02:25:36 +03:00
using Mirea.Api.Endpoint.Configuration.Validation.Attributes;
using Mirea.Api.Endpoint.Configuration.Validation.Interfaces;
2024-06-01 10:59:23 +03:00
using System;
using System.Text.Json.Serialization;
2024-10-07 02:25:36 +03:00
namespace Mirea.Api.Endpoint.Configuration.Model.GeneralSettings;
[RequiredSettings]
public class DbSettings : IIsConfigured
{
public enum DatabaseEnum
{
Mysql,
Sqlite,
PostgresSql
}
public DatabaseEnum TypeDatabase { get; set; }
public required string ConnectionStringSql { get; set; }
[JsonIgnore]
public DatabaseProvider DatabaseProvider =>
TypeDatabase switch
{
DatabaseEnum.PostgresSql => DatabaseProvider.Postgresql,
DatabaseEnum.Mysql => DatabaseProvider.Mysql,
DatabaseEnum.Sqlite => DatabaseProvider.Sqlite,
_ => throw new ArgumentOutOfRangeException()
};
public bool IsConfigured() =>
!string.IsNullOrEmpty(ConnectionStringSql);
}