ChangeEvent

Struct ChangeEvent 

Source
pub struct ChangeEvent {
    pub event_type: EventType,
    pub lsn: Lsn,
    pub metadata: Option<HashMap<String, Value>>,
}
Expand description

Represents a single change event from PostgreSQL logical replication

Fields§

§event_type: EventType

Type of the event with embedded data

§lsn: Lsn

LSN (Log Sequence Number) position

§metadata: Option<HashMap<String, Value>>

Additional metadata

Implementations§

Source§

impl ChangeEvent

Source

pub fn insert( schema_name: String, table_name: String, relation_oid: u32, data: HashMap<String, Value>, lsn: Lsn, ) -> ChangeEvent

Create a new INSERT event

§Arguments
  • schema_name - Database schema name
  • table_name - Table name
  • relation_oid - PostgreSQL relation OID
  • data - Inserted row data as column_name -> value map
  • lsn - Log Sequence Number for this event
§Example
use pg_walstream::{ChangeEvent, Lsn};
use std::collections::HashMap;

let mut data = HashMap::new();
data.insert("id".to_string(), serde_json::json!(1));
data.insert("name".to_string(), serde_json::json!("Alice"));

let event = ChangeEvent::insert(
    "public".to_string(),
    "users".to_string(),
    12345,
    data,
    Lsn::new(0x16B374D848),
);
Source

pub fn update( schema_name: String, table_name: String, relation_oid: u32, old_data: Option<HashMap<String, Value>>, new_data: HashMap<String, Value>, replica_identity: ReplicaIdentity, key_columns: Vec<String>, lsn: Lsn, ) -> ChangeEvent

Create a new UPDATE event

§Arguments
  • schema_name - Database schema name
  • table_name - Table name
  • relation_oid - PostgreSQL relation OID
  • old_data - Previous row data (may be None depending on replica identity)
  • new_data - New row data after update
  • replica_identity - Table’s replica identity setting (affects old_data availability)
  • key_columns - Names of columns that form the replica identity key
  • lsn - Log Sequence Number for this event
§Example
use pg_walstream::{ChangeEvent, ReplicaIdentity, Lsn};
use std::collections::HashMap;

let mut old_data = HashMap::new();
old_data.insert("id".to_string(), serde_json::json!(1));
old_data.insert("name".to_string(), serde_json::json!("Alice"));

let mut new_data = HashMap::new();
new_data.insert("id".to_string(), serde_json::json!(1));
new_data.insert("name".to_string(), serde_json::json!("Bob"));

let event = ChangeEvent::update(
    "public".to_string(),
    "users".to_string(),
    12345,
    Some(old_data),
    new_data,
    ReplicaIdentity::Default,
    vec!["id".to_string()],
    Lsn::new(0x16B374D848),
);
Source

pub fn delete( schema_name: String, table_name: String, relation_oid: u32, old_data: HashMap<String, Value>, replica_identity: ReplicaIdentity, key_columns: Vec<String>, lsn: Lsn, ) -> ChangeEvent

Create a new DELETE event

§Arguments
  • schema_name - Database schema name
  • table_name - Table name
  • relation_oid - PostgreSQL relation OID
  • old_data - Deleted row data (columns available depend on replica identity)
  • replica_identity - Table’s replica identity setting
  • key_columns - Names of columns that form the replica identity key
  • lsn - Log Sequence Number for this event
§Example
use pg_walstream::{ChangeEvent, ReplicaIdentity, Lsn};
use std::collections::HashMap;

let mut old_data = HashMap::new();
old_data.insert("id".to_string(), serde_json::json!(1));
old_data.insert("name".to_string(), serde_json::json!("Alice"));

let event = ChangeEvent::delete(
    "public".to_string(),
    "users".to_string(),
    12345,
    old_data,
    ReplicaIdentity::Full,
    vec!["id".to_string()],
    Lsn::new(0x16B374D848),
);
Source

pub fn begin( transaction_id: u32, final_lsn: Lsn, commit_timestamp: DateTime<Utc>, lsn: Lsn, ) -> ChangeEvent

Create a BEGIN transaction event

Marks the beginning of a transaction in the replication stream.

§Arguments
  • transaction_id - PostgreSQL transaction ID (XID)
  • final_lsn - The final LSN of the transaction
  • commit_timestamp - Transaction start timestamp
  • lsn - Log Sequence Number for this event
Source

pub fn commit( commit_timestamp: DateTime<Utc>, lsn: Lsn, commit_lsn: Lsn, end_lsn: Lsn, ) -> ChangeEvent

Create a COMMIT transaction event

Marks the successful commit of a transaction in the replication stream.

§Arguments
  • commit_timestamp - Transaction commit timestamp
  • lsn - Log Sequence Number for this event
Source

pub fn truncate(tables: Vec<String>, lsn: Lsn) -> ChangeEvent

Create a TRUNCATE event

§Arguments
  • tables - List of table names that were truncated
  • lsn - Log Sequence Number for this event
Source

pub fn relation(lsn: Lsn) -> ChangeEvent

Create a RELATION event

§Arguments
  • lsn - Log Sequence Number for this event
Source

pub fn type_event(lsn: Lsn) -> ChangeEvent

Create a TYPE event

§Arguments
  • lsn - Log Sequence Number for this event
Source

pub fn origin(lsn: Lsn) -> ChangeEvent

Create an ORIGIN event

§Arguments
  • lsn - Log Sequence Number for this event
Source

pub fn message(lsn: Lsn) -> ChangeEvent

Create a MESSAGE event

§Arguments
  • lsn - Log Sequence Number for this event
Source

pub fn with_metadata(self, metadata: HashMap<String, Value>) -> ChangeEvent

Set metadata for this event

Source

pub fn get_key_columns(&self) -> Option<&Vec<String>>

Get key columns from UPDATE or DELETE events

Source

pub fn get_replica_identity(&self) -> Option<&ReplicaIdentity>

Get replica identity from UPDATE or DELETE events

Source

pub fn event_type_str(&self) -> &str

Trait Implementations§

Source§

impl Clone for ChangeEvent

Source§

fn clone(&self) -> ChangeEvent

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ChangeEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ChangeEvent

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<ChangeEvent, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ChangeEvent

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,