Skip to content

Commit edffdf1

Browse files
committed
Add NpgsqlDataSource support to PostgresqlConnectionManager
1 parent 9603453 commit edffdf1

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/dbup-postgresql/PostgresqlConnectionManager.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ public PostgresqlConnectionManager(string connectionString, X509Certificate2 cer
3939
{
4040
}
4141

42+
#if (NETSTANDARD2_0_OR_GREATER || NET462_OR_GREATER)
43+
/// <summary>
44+
/// Creates a new PostgreSQL database connection with a NpgsqlDatasource
45+
/// </summary>
46+
/// <param name="datasource">The PostgreSQL NpgsqlDataSource.</param>
47+
public PostgresqlConnectionManager(NpgsqlDataSource datasource)
48+
: base(new DelegateConnectionFactory(l => datasource.CreateConnection()))
49+
{
50+
}
51+
#endif
52+
4253
/// <summary>
4354
/// Splits the statements in the script using the ";" character.
4455
/// </summary>

src/dbup-postgresql/Properties/AssemblyInfo.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
using System.Runtime.InteropServices;
33

44
[assembly: ComVisible(false)]
5+
6+
#if (NETSTANDARD2_0_OR_GREATER || NET462_OR_GREATER)
7+
// Npgsql is not CLS compliant and PostgresqlConnectionManager exposes types like NpgsqlDataSource
8+
[assembly: CLSCompliant(false)]
9+
#else
510
[assembly: CLSCompliant(true)]
11+
#endif
612

713
// The following GUID is for the ID of the typelib if this project is exposed to COM
814
[assembly: Guid("5ddc04cc-0bd3-421e-9ae4-9fd0e4f4ef04")]

src/dbup-postgresql/dbup-postgresql.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
<ItemGroup>
2020
<PackageReference Include="dbup-core" Version="5.0.37"/>
2121
<!-- <PackageReference Include="System.Net.Security" Version="4.3.2"/>-->
22-
<PackageReference Include="Npgsql" Version="3.2.7"/>
22+
<PackageReference Include="Npgsql" Version="3.2.7" Condition=" '$(TargetFramework)' == 'netstandard1.3' " />
23+
<PackageReference Include="Npgsql" Version="8.0.2" Condition=" '$(TargetFramework)' == 'netstandard2.0' " />
24+
<PackageReference Include="Npgsql" Version="8.0.2" Condition=" '$(TargetFramework)' == 'net462' " />
2325
</ItemGroup>
2426

2527
<ItemGroup>

0 commit comments

Comments
 (0)