Skip to content

Commit

Permalink
[#487] [add] PostgreSQL dialect
Browse files Browse the repository at this point in the history
  • Loading branch information
i4004 committed Jan 13, 2024
1 parent a1f6d1f commit d83acb5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"indicies",
"langword",
"localizable",
"Postgre",
"registrator",
"seealso",
"serializer",
Expand Down
21 changes: 17 additions & 4 deletions src/Simplify.FluentNHibernate/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ public static FluentConfiguration InitializeFromConfigPostgreSql(this FluentConf
/// <param name="configuration">The configuration containing database config section.</param>
/// <param name="configSectionName">Database configuration section name in configuration.</param>
/// <param name="additionalClientConfiguration">The additional client configuration.</param>
/// <param name="dialect">The dialect.</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException">
/// fluentConfiguration
Expand All @@ -408,23 +409,35 @@ public static FluentConfiguration InitializeFromConfigPostgreSql(this FluentConf
public static FluentConfiguration InitializeFromConfigPostgreSql(this FluentConfiguration fluentConfiguration,
IConfiguration configuration,
string configSectionName = "DatabaseConnectionSettings",
Action<PostgreSQLConfiguration>? additionalClientConfiguration = null)
Action<PostgreSQLConfiguration>? additionalClientConfiguration = null,
PostgreSqlDialect dialect = PostgreSqlDialect.PostgreSQL83)
{
if (fluentConfiguration == null) throw new ArgumentNullException(nameof(fluentConfiguration));
if (configuration == null) throw new ArgumentNullException(nameof(configuration));

InitializeFromConfigPostgreSql(fluentConfiguration,
new ConfigurationBasedDbConnectionSettings(configuration, configSectionName),
additionalClientConfiguration);
additionalClientConfiguration,
dialect);

return fluentConfiguration;
}

private static void InitializeFromConfigPostgreSql(FluentConfiguration fluentConfiguration,
DbConnectionSettings settings,
Action<PostgreSQLConfiguration>? additionalClientConfiguration = null)
Action<PostgreSQLConfiguration>? additionalClientConfiguration = null,
PostgreSqlDialect dialect = PostgreSqlDialect.PostgreSQL83)
{
var clientConfiguration = PostgreSQLConfiguration.PostgreSQL82.ConnectionString(c => c
var clientConfiguration = dialect switch
{
PostgreSqlDialect.Standard => PostgreSQLConfiguration.Standard,
PostgreSqlDialect.PostgreSQL81 => PostgreSQLConfiguration.PostgreSQL81,
PostgreSqlDialect.PostgreSQL82 => PostgreSQLConfiguration.PostgreSQL82,
PostgreSqlDialect.PostgreSQL83 => PostgreSQLConfiguration.PostgreSQL83,
_ => throw new InvalidOperationException()
};

clientConfiguration.ConnectionString(c => c
.Host(settings.ServerName)
.Port(settings.Port ?? 5432)
.Database(settings.DataBaseName)
Expand Down
25 changes: 25 additions & 0 deletions src/Simplify.FluentNHibernate/PostgreSqlDialect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Simplify.FluentNHibernate
{
/// <summary>
/// Provides PostgreSQL dialect
/// </summary>
public enum PostgreSqlDialect
{
/// <summary>
/// The standard dialect
/// </summary>
Standard,
/// <summary>
/// The PostgreSQL 8.1 dialect
/// </summary>
PostgreSQL81,
/// <summary>
/// The PostgreSQL 8.2 dialect
/// </summary>
PostgreSQL82,
/// <summary>
/// The PostgreSQL 8.3 dialect
/// </summary>
PostgreSQL83
}
}

0 comments on commit d83acb5

Please sign in to comment.