Skip to content

Commit

Permalink
Add the field (column) name to ReplicationValue (npgsql#5719)
Browse files Browse the repository at this point in the history
* Add the field (column) name to ReplicationValue and add test for field information accessor methods

Closes npgsql#5718
  • Loading branch information
Brar authored Jun 28, 2024
1 parent 3592cee commit d36b2f5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Npgsql/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
Npgsql.NpgsqlSlimDataSourceBuilder.EnableGeometricTypes() -> Npgsql.NpgsqlSlimDataSourceBuilder!
Npgsql.NpgsqlSlimDataSourceBuilder.EnableJsonTypes() -> Npgsql.NpgsqlSlimDataSourceBuilder!
Npgsql.NpgsqlSlimDataSourceBuilder.EnableNetworkTypes() -> Npgsql.NpgsqlSlimDataSourceBuilder!
Npgsql.Replication.PgOutput.ReplicationValue.GetFieldName() -> string!
6 changes: 6 additions & 0 deletions src/Npgsql/Replication/PgOutput/ReplicationValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public bool IsUnchangedToastedValue
/// <returns>The data type of the specified column.</returns>
public Type GetFieldType() => _fieldDescription.FieldType;

/// <summary>
/// Gets the name of the specified column.
/// </summary>
/// <returns>The name of the specified column.</returns>
public string GetFieldName() => _fieldDescription.Name;

/// <summary>
/// Gets the value of the specified column as a type.
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions test/Npgsql.Tests/Replication/PgOutputReplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,27 @@ public Task Insert()
Assert.That(insertMsg.Relation, Is.SameAs(relationMsg));
var columnEnumerator = insertMsg.NewRow.GetAsyncEnumerator();
Assert.That(await columnEnumerator.MoveNextAsync(), Is.True);
var postgresType = columnEnumerator.Current.GetPostgresType();
Assert.That(postgresType.FullName, Is.EqualTo("pg_catalog.integer"));
Assert.That(columnEnumerator.Current.GetDataTypeName(), Is.EqualTo("integer"));
Assert.That(columnEnumerator.Current.GetFieldName(), Is.EqualTo("id"));
if (IsBinary)
{
Assert.That(columnEnumerator.Current.GetFieldType(), Is.EqualTo(typeof(int)));
Assert.That(await columnEnumerator.Current.Get<int>(), Is.EqualTo(1));
}
else
{
Assert.That(columnEnumerator.Current.GetFieldType(), Is.EqualTo(typeof(string)));
Assert.That(await columnEnumerator.Current.Get<string>(), Is.EqualTo("1"));
}
Assert.That(await columnEnumerator.MoveNextAsync(), Is.True);
postgresType = columnEnumerator.Current.GetPostgresType();
Assert.That(postgresType.FullName, Is.EqualTo("pg_catalog.text"));
Assert.That(columnEnumerator.Current.GetDataTypeName(), Is.EqualTo("text"));
Assert.That(columnEnumerator.Current.GetFieldType(), Is.EqualTo(typeof(string)));
Assert.That(columnEnumerator.Current.GetFieldName(), Is.EqualTo("name"));
Assert.That(columnEnumerator.Current.IsDBNull, Is.False);
Assert.That(await columnEnumerator.Current.Get<string>(), Is.EqualTo("val1"));
Assert.That(await columnEnumerator.MoveNextAsync(), Is.False);
Expand Down

0 comments on commit d36b2f5

Please sign in to comment.