-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NpgsqlPgLsnTypeMapping to map the pg_lsn internal type (#2165)
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/EFCore.PG/Storage/Internal/Mapping/NpgsqlPgLsnTypeMapping.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using NpgsqlTypes; | ||
using System.Text; | ||
|
||
namespace Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; | ||
|
||
/// <summary> | ||
/// The type mapping for the PostgreSQL pg_lsn type. | ||
/// </summary> | ||
/// <remarks> | ||
/// See: https://www.postgresql.org/docs/current/datatype-pg-lsn.html | ||
/// </remarks> | ||
public class NpgsqlPgLsnTypeMapping : NpgsqlTypeMapping | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="NpgsqlPgLsnTypeMapping"/> class. | ||
/// </summary> | ||
public NpgsqlPgLsnTypeMapping() | ||
: base("pg_lsn", typeof(NpgsqlLogSequenceNumber), NpgsqlDbType.PgLsn) {} | ||
|
||
protected NpgsqlPgLsnTypeMapping(RelationalTypeMappingParameters parameters) | ||
: base(parameters, NpgsqlDbType.PgLsn) {} | ||
|
||
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) | ||
=> new NpgsqlPgLsnTypeMapping(parameters); | ||
|
||
protected override string GenerateNonNullSqlLiteral(object value) | ||
{ | ||
var lsn = (NpgsqlLogSequenceNumber)value; | ||
var builder = new StringBuilder("PG_LSN '") | ||
.Append(lsn.ToString()) | ||
.Append('\''); | ||
return builder.ToString(); | ||
} | ||
|
||
public override Expression GenerateCodeLiteral(object value) | ||
{ | ||
var lsn = (NpgsqlLogSequenceNumber)value; | ||
return Expression.New(Constructor, Expression.Constant((ulong)lsn)); | ||
} | ||
|
||
private static readonly ConstructorInfo Constructor = | ||
typeof(NpgsqlLogSequenceNumber).GetConstructor(new[] { typeof(ulong) })!; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters