From d83acb54e0e838525bdbbeabd7e3341804ff2a88 Mon Sep 17 00:00:00 2001 From: Alexanderius Date: Sat, 13 Jan 2024 23:41:39 +0600 Subject: [PATCH] [#487] [add] PostgreSQL dialect --- .vscode/settings.json | 1 + .../ConfigurationExtensions.cs | 21 +++++++++++++--- .../PostgreSqlDialect.cs | 25 +++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 src/Simplify.FluentNHibernate/PostgreSqlDialect.cs diff --git a/.vscode/settings.json b/.vscode/settings.json index 7356fbf9..64eef6f2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,6 +9,7 @@ "indicies", "langword", "localizable", + "Postgre", "registrator", "seealso", "serializer", diff --git a/src/Simplify.FluentNHibernate/ConfigurationExtensions.cs b/src/Simplify.FluentNHibernate/ConfigurationExtensions.cs index 975b6241..50931838 100644 --- a/src/Simplify.FluentNHibernate/ConfigurationExtensions.cs +++ b/src/Simplify.FluentNHibernate/ConfigurationExtensions.cs @@ -399,6 +399,7 @@ public static FluentConfiguration InitializeFromConfigPostgreSql(this FluentConf /// The configuration containing database config section. /// Database configuration section name in configuration. /// The additional client configuration. + /// The dialect. /// /// /// fluentConfiguration @@ -408,23 +409,35 @@ public static FluentConfiguration InitializeFromConfigPostgreSql(this FluentConf public static FluentConfiguration InitializeFromConfigPostgreSql(this FluentConfiguration fluentConfiguration, IConfiguration configuration, string configSectionName = "DatabaseConnectionSettings", - Action? additionalClientConfiguration = null) + Action? 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? additionalClientConfiguration = null) + Action? 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) diff --git a/src/Simplify.FluentNHibernate/PostgreSqlDialect.cs b/src/Simplify.FluentNHibernate/PostgreSqlDialect.cs new file mode 100644 index 00000000..3f10d8f7 --- /dev/null +++ b/src/Simplify.FluentNHibernate/PostgreSqlDialect.cs @@ -0,0 +1,25 @@ +namespace Simplify.FluentNHibernate +{ + /// + /// Provides PostgreSQL dialect + /// + public enum PostgreSqlDialect + { + /// + /// The standard dialect + /// + Standard, + /// + /// The PostgreSQL 8.1 dialect + /// + PostgreSQL81, + /// + /// The PostgreSQL 8.2 dialect + /// + PostgreSQL82, + /// + /// The PostgreSQL 8.3 dialect + /// + PostgreSQL83 + } +} \ No newline at end of file