Skip to content

Commit 00f9f89

Browse files
authored
NpgsqlConnector refactoring (removed NpgsqlConnection from Open) (#3669)
Closes #3668
1 parent f380724 commit 00f9f89

63 files changed

Lines changed: 275 additions & 215 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Npgsql.GeoJSON/Internal/GeoJSONHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ public GeoJSONHandlerFactory(GeoJSONOptions options = GeoJSONOptions.None)
2222

2323
static readonly ConcurrentDictionary<string, CrsMap> s_crsMaps = new();
2424

25-
public override NpgsqlTypeHandler<GeoJSONObject> Create(PostgresType postgresType, NpgsqlConnection conn)
25+
public override NpgsqlTypeHandler<GeoJSONObject> Create(PostgresType postgresType, NpgsqlConnector conn)
2626
{
2727
var crsMap = (_options & (GeoJSONOptions.ShortCRS | GeoJSONOptions.LongCRS)) == GeoJSONOptions.None
28-
? default : s_crsMaps.GetOrAdd(conn.ConnectionString, _ =>
28+
? default : s_crsMaps.GetOrAdd(conn.Settings.ConnectionString, _ =>
2929
{
3030
var builder = new CrsMapBuilder();
31-
using (var cmd = new NpgsqlCommand(
31+
using (var cmd = conn.CreateCommand(
3232
"SELECT min(srid), max(srid), auth_name " +
3333
"FROM(SELECT srid, auth_name, srid - rank() OVER(ORDER BY srid) AS range " +
34-
"FROM spatial_ref_sys) AS s GROUP BY range, auth_name ORDER BY 1;", conn))
34+
"FROM spatial_ref_sys) AS s GROUP BY range, auth_name ORDER BY 1;"))
3535
using (var reader = cmd.ExecuteReader())
3636
while (reader.Read())
3737
{

src/Npgsql.Json.NET/Internal/JsonHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ public class JsonHandlerFactory : NpgsqlTypeHandlerFactory<string>
1616
public JsonHandlerFactory(JsonSerializerSettings? settings = null)
1717
=> _settings = settings ?? new JsonSerializerSettings();
1818

19-
public override NpgsqlTypeHandler<string> Create(PostgresType postgresType, NpgsqlConnection conn)
19+
public override NpgsqlTypeHandler<string> Create(PostgresType postgresType, NpgsqlConnector conn)
2020
=> new JsonHandler(postgresType, conn, _settings);
2121
}
2222

2323
class JsonHandler : Npgsql.Internal.TypeHandlers.JsonHandler
2424
{
2525
readonly JsonSerializerSettings _settings;
2626

27-
public JsonHandler(PostgresType postgresType, NpgsqlConnection connection, JsonSerializerSettings settings)
28-
: base(postgresType, connection, isJsonb: false) => _settings = settings;
27+
public JsonHandler(PostgresType postgresType, NpgsqlConnector connector, JsonSerializerSettings settings)
28+
: base(postgresType, connector, isJsonb: false) => _settings = settings;
2929

3030
protected override async ValueTask<T> Read<T>(NpgsqlReadBuffer buf, int len, bool async, FieldDescription? fieldDescription = null)
3131
{

src/Npgsql.Json.NET/Internal/JsonbHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ public class JsonbHandlerFactory : NpgsqlTypeHandlerFactory<string>
1616
public JsonbHandlerFactory(JsonSerializerSettings? settings = null)
1717
=> _settings = settings ?? new JsonSerializerSettings();
1818

19-
public override NpgsqlTypeHandler<string> Create(PostgresType postgresType, NpgsqlConnection conn)
19+
public override NpgsqlTypeHandler<string> Create(PostgresType postgresType, NpgsqlConnector conn)
2020
=> new JsonbHandler(postgresType, conn, _settings);
2121
}
2222

2323
class JsonbHandler : Npgsql.Internal.TypeHandlers.JsonHandler
2424
{
2525
readonly JsonSerializerSettings _settings;
2626

27-
public JsonbHandler(PostgresType postgresType, NpgsqlConnection connection, JsonSerializerSettings settings)
28-
: base(postgresType, connection, isJsonb: true) => _settings = settings;
27+
public JsonbHandler(PostgresType postgresType, NpgsqlConnector connector, JsonSerializerSettings settings)
28+
: base(postgresType, connector, isJsonb: true) => _settings = settings;
2929

3030
protected override async ValueTask<T> Read<T>(NpgsqlReadBuffer buf, int len, bool async, FieldDescription? fieldDescription = null)
3131
{

src/Npgsql.LegacyPostgis/Internal/LegacyPostgisHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Npgsql.LegacyPostgis.Internal
1010
{
1111
public class LegacyPostgisHandlerFactory : NpgsqlTypeHandlerFactory<PostgisGeometry>
1212
{
13-
public override NpgsqlTypeHandler<PostgisGeometry> Create(PostgresType postgresType, NpgsqlConnection conn)
13+
public override NpgsqlTypeHandler<PostgisGeometry> Create(PostgresType postgresType, NpgsqlConnector conn)
1414
=> new LegacyPostgisHandler(postgresType);
1515
}
1616

src/Npgsql.NetTopologySuite/Internal/NetTopologySuiteHandlerFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using NetTopologySuite.Geometries;
33
using NetTopologySuite.IO;
4+
using Npgsql.Internal;
45
using Npgsql.Internal.TypeHandling;
56
using Npgsql.PostgresTypes;
67

@@ -17,7 +18,7 @@ internal NetTopologySuiteHandlerFactory(PostGisReader reader, PostGisWriter writ
1718
_writer = writer ?? throw new ArgumentNullException(nameof(writer));
1819
}
1920

20-
public override NpgsqlTypeHandler<Geometry> Create(PostgresType postgresType, NpgsqlConnection conn)
21+
public override NpgsqlTypeHandler<Geometry> Create(PostgresType postgresType, NpgsqlConnector conn)
2122
=> new NetTopologySuiteHandler(postgresType, _reader, _writer);
2223
}
2324
}

src/Npgsql.NodaTime/Internal/DateHandler.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ namespace Npgsql.NodaTime.Internal
1111
{
1212
public class DateHandlerFactory : NpgsqlTypeHandlerFactory<LocalDate>
1313
{
14-
public override NpgsqlTypeHandler<LocalDate> Create(PostgresType postgresType, NpgsqlConnection conn)
15-
{
16-
var csb = new NpgsqlConnectionStringBuilder(conn.ConnectionString);
17-
return new DateHandler(postgresType, csb.ConvertInfinityDateTime);
18-
}
14+
public override NpgsqlTypeHandler<LocalDate> Create(PostgresType postgresType, NpgsqlConnector conn)
15+
=> new DateHandler(postgresType, conn.Settings.ConvertInfinityDateTime);
1916
}
2017

2118
sealed partial class DateHandler : NpgsqlSimpleTypeHandler<LocalDate>, INpgsqlSimpleTypeHandler<DateTime>, INpgsqlSimpleTypeHandler<NpgsqlDate>

src/Npgsql.NodaTime/Internal/IntervalHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace Npgsql.NodaTime.Internal
1212
public class IntervalHandlerFactory : NpgsqlTypeHandlerFactory<Period>
1313
{
1414
// Check for the legacy floating point timestamps feature
15-
public override NpgsqlTypeHandler<Period> Create(PostgresType postgresType, NpgsqlConnection conn)
16-
=> conn.HasIntegerDateTimes
15+
public override NpgsqlTypeHandler<Period> Create(PostgresType postgresType, NpgsqlConnector conn)
16+
=> conn.DatabaseInfo.HasIntegerDateTimes
1717
? new IntervalHandler(postgresType)
1818
: throw new NotSupportedException($"The deprecated floating-point date/time format is not supported by {nameof(Npgsql)}.");
1919
}

src/Npgsql.NodaTime/Internal/TimeHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ namespace Npgsql.NodaTime.Internal
1313
public class TimeHandlerFactory : NpgsqlTypeHandlerFactory<LocalTime>
1414
{
1515
// Check for the legacy floating point timestamps feature
16-
public override NpgsqlTypeHandler<LocalTime> Create(PostgresType postgresType, NpgsqlConnection conn)
17-
=> conn.HasIntegerDateTimes
16+
public override NpgsqlTypeHandler<LocalTime> Create(PostgresType postgresType, NpgsqlConnector conn)
17+
=> conn.DatabaseInfo.HasIntegerDateTimes
1818
? new TimeHandler(postgresType)
1919
: throw new NotSupportedException($"The deprecated floating-point date/time format is not supported by {nameof(Npgsql)}.");
2020
}

src/Npgsql.NodaTime/Internal/TimeTzHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ namespace Npgsql.NodaTime.Internal
1111
public class TimeTzHandlerFactory : NpgsqlTypeHandlerFactory<OffsetTime>
1212
{
1313
// Check for the legacy floating point timestamps feature
14-
public override NpgsqlTypeHandler<OffsetTime> Create(PostgresType postgresType, NpgsqlConnection conn)
15-
=> conn.HasIntegerDateTimes
14+
public override NpgsqlTypeHandler<OffsetTime> Create(PostgresType postgresType, NpgsqlConnector conn)
15+
=> conn.DatabaseInfo.HasIntegerDateTimes
1616
? new TimeTzHandler(postgresType)
1717
: throw new NotSupportedException($"The deprecated floating-point date/time format is not supported by {nameof(Npgsql)}.");
1818
}

src/Npgsql.NodaTime/Internal/TimestampHandler.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ namespace Npgsql.NodaTime.Internal
1111
{
1212
public class TimestampHandlerFactory : NpgsqlTypeHandlerFactory<Instant>
1313
{
14-
public override NpgsqlTypeHandler<Instant> Create(PostgresType postgresType, NpgsqlConnection conn)
14+
public override NpgsqlTypeHandler<Instant> Create(PostgresType postgresType, NpgsqlConnector conn)
1515
{
16-
if (!conn.HasIntegerDateTimes)
16+
if (!conn.DatabaseInfo.HasIntegerDateTimes)
1717
throw new NotSupportedException($"The deprecated floating-point date/time format is not supported by {nameof(Npgsql)}.");
1818

19-
var csb = new NpgsqlConnectionStringBuilder(conn.ConnectionString);
20-
return new TimestampHandler(postgresType, csb.ConvertInfinityDateTime);
19+
return new TimestampHandler(postgresType, conn.Settings.ConvertInfinityDateTime);
2120
}
2221
}
2322

0 commit comments

Comments
 (0)