using NpgsqlTypes; using System; using System.Collections.Generic; using System.Collections.Immutable; using Npgsql.BackendMessages; namespace Npgsql.Replication.PgOutput.Messages; /// /// Logical Replication Protocol relation message /// public sealed class RelationMessage : TransactionalMessage { /// /// ID of the relation. /// public uint RelationId { get; private set; } /// /// Namespace (empty string for pg_catalog). /// public string Namespace { get; private set; } = string.Empty; /// /// Relation name. /// public string RelationName { get; private set; } = string.Empty; /// /// Replica identity setting for the relation (same as relreplident in pg_class): /// columns used to form “replica identity” for rows. /// public ReplicaIdentitySetting ReplicaIdentity { get; private set; } /// /// Relation columns /// public IReadOnlyList Columns => InternalColumns; internal ReadOnlyArrayBuffer InternalColumns { get; } = new(); internal RowDescriptionMessage RowDescription { get; set; } = null!; internal RelationMessage() {} internal RelationMessage Populate( NpgsqlLogSequenceNumber walStart, NpgsqlLogSequenceNumber walEnd, DateTime serverClock, uint? transactionXid, uint relationId, string ns, string relationName, ReplicaIdentitySetting relationReplicaIdentitySetting) { base.Populate(walStart, walEnd, serverClock, transactionXid); RelationId = relationId; Namespace = ns; RelationName = relationName; ReplicaIdentity = relationReplicaIdentitySetting; return this; } /// /// Represents a column in a Logical Replication Protocol relation message /// public readonly struct Column { internal Column(ColumnFlags flags, string columnName, uint dataTypeId, int typeModifier) { Flags = flags; ColumnName = columnName; DataTypeId = dataTypeId; TypeModifier = typeModifier; } /// /// Flags for the column. /// public ColumnFlags Flags { get; } /// /// Name of the column. /// public string ColumnName { get; } /// /// ID of the column's data type. /// public uint DataTypeId { get; } /// /// Type modifier of the column (atttypmod). /// public int TypeModifier { get; } /// /// Flags for the column. /// [Flags] public enum ColumnFlags { /// /// No flags. /// None = 0, /// /// Marks the column as part of the key. /// PartOfKey = 1 } } /// /// Replica identity setting for the relation (same as relreplident in pg_class). /// /// /// See /// public enum ReplicaIdentitySetting : byte { /// /// Default (primary key, if any). /// Default = (byte)'d', /// /// Nothing. /// Nothing = (byte)'n', /// /// All columns. /// AllColumns = (byte)'f', /// /// Index with indisreplident set (same as nothing if the index used has been dropped) /// IndexWithIndIsReplIdent = (byte)'i' } }