2025-02-11 17:07:01 +01:00
|
|
|
|
using Autofac;
|
2025-03-10 15:56:22 +01:00
|
|
|
|
using PlanTempus.Core.Database;
|
|
|
|
|
|
using PlanTempus.Core.Database.ConnectionFactory;
|
2025-03-03 17:40:16 +01:00
|
|
|
|
|
2025-02-20 00:23:13 +01:00
|
|
|
|
namespace PlanTempus.Database.ModuleRegistry
|
2026-01-10 11:13:33 +01:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public class DbPostgreSqlModule : Module
|
2025-02-20 00:23:13 +01:00
|
|
|
|
{
|
|
|
|
|
|
public required string ConnectionString { get; set; }
|
2025-02-21 00:30:04 +01:00
|
|
|
|
|
2025-02-20 00:23:13 +01:00
|
|
|
|
protected override void Load(ContainerBuilder builder)
|
|
|
|
|
|
{
|
2026-01-10 11:13:33 +01:00
|
|
|
|
Insight.Database.Providers.PostgreSQL.PostgreSQLInsightDbProvider.RegisterProvider();
|
|
|
|
|
|
Insight.Database.ColumnMapping.Tables.AddMapper(new SnakeCaseToPascalCaseMapper());
|
2025-03-03 17:40:16 +01:00
|
|
|
|
builder.RegisterType<PostgresConnectionFactory>()
|
|
|
|
|
|
.As<IDbConnectionFactory>()
|
2025-02-21 23:34:06 +01:00
|
|
|
|
.WithParameter(new TypedParameter(typeof(string), ConnectionString))
|
|
|
|
|
|
.SingleInstance();
|
2025-02-21 00:30:04 +01:00
|
|
|
|
|
2025-03-03 17:40:16 +01:00
|
|
|
|
builder.RegisterType<SqlOperations>()
|
|
|
|
|
|
.As<IDatabaseOperations>();
|
2025-02-21 00:30:04 +01:00
|
|
|
|
}
|
2026-01-10 11:13:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class SnakeCaseToPascalCaseMapper : Insight.Database.Mapping.IColumnMapper
|
|
|
|
|
|
{
|
|
|
|
|
|
public string MapColumn(Type type, System.Data.IDataReader reader, int column)
|
|
|
|
|
|
{
|
|
|
|
|
|
string databaseName = reader.GetName(column);
|
|
|
|
|
|
|
|
|
|
|
|
var parts = databaseName.Split(['_'], StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
|
var pascalName = string.Concat(parts.Select(p =>
|
|
|
|
|
|
p.Substring(0, 1).ToUpper() + p.Substring(1).ToLower()
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
return pascalName;
|
|
|
|
|
|
}
|
2025-02-21 00:30:04 +01:00
|
|
|
|
}
|
2025-02-11 17:07:01 +01:00
|
|
|
|
}
|