31 lines
982 B
C#
31 lines
982 B
C#
|
|
using System.Data;
|
||
|
|
using Core.Configurations.SmartConfiguration;
|
||
|
|
using Insight.Database;
|
||
|
|
|
||
|
|
namespace Core.Configurations.SmartConfigProvider;
|
||
|
|
public class ConfigurationRepository : IConfigurationRepository
|
||
|
|
{
|
||
|
|
private readonly IDbConnection _connection;
|
||
|
|
|
||
|
|
public ConfigurationRepository(IDbConnection connection)
|
||
|
|
{
|
||
|
|
_connection = connection;
|
||
|
|
}
|
||
|
|
public ConfigurationRepository(string connectionString)
|
||
|
|
{
|
||
|
|
_connection = new Npgsql.NpgsqlConnection(connectionString);
|
||
|
|
}
|
||
|
|
public IEnumerable<AppConfiguration> GetActiveConfigurations()
|
||
|
|
{
|
||
|
|
const string sql = @"
|
||
|
|
SELECT id, ""key"", value, label, content_type,
|
||
|
|
valid_from, expires_at, created_at, modified_at, etag
|
||
|
|
FROM app_configuration
|
||
|
|
WHERE CURRENT_TIMESTAMP BETWEEN valid_from AND expires_at
|
||
|
|
OR (valid_from IS NULL AND expires_at IS NULL)";
|
||
|
|
|
||
|
|
|
||
|
|
return _connection.QuerySql<AppConfiguration>(sql);
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|