Skip to main content

Module database_event

Module database_event 

Source
Expand description

Database event types and serialization.

This module provides types for database replication events (COPY, CDC, proxy) with FlexBuffers serialization for efficient wire format.

§Design

The key design decision is storing PostgreSQL binary format bytes directly in ColumnValue.data to enable zero-copy for the high-throughput COPY path.

§Example

use scry_protocol::database_event::{
    DatabaseEventBuilder, BatchBuilder, Row, ColumnValue, TypeTag,
    serialize_batch, read_batch,
};

// Build an event
let event = DatabaseEventBuilder::insert("public", "users")
    .position(12345)
    .new_row(Row::new(vec![
        ColumnValue::from_pg_binary(TypeTag::Int32, 23, vec![0, 0, 0, 1]),
    ]))
    .build();

// Build a batch
let mut builder = BatchBuilder::new().source_id("my-source");
builder.add_event(event);
let batch = builder.finish().unwrap();

// Serialize
let bytes = serialize_batch(&batch).unwrap();

// Deserialize
let recovered = read_batch(&bytes).unwrap();

Structs§

BatchBuilder
Builder for constructing batches of events with efficient serialization.
ColumnMeta
Column metadata.
ColumnValue
A single column value. Uses raw PostgreSQL binary format bytes for zero-copy efficiency.
DatabaseEvent
A single database event.
DatabaseEventBatch
Batch of events for efficient transport.
DatabaseEventBuilder
Builder for constructing a single DatabaseEvent.
RelationMeta
Relation (table) metadata.
Row
A row of column values.
SequenceValue
A PostgreSQL sequence value for synchronization.

Enums§

ControlDirective
Control directive for coordinating producer/receiver behavior.
OperationType
Database operation type.
ReplicaIdentity
PostgreSQL replica identity setting.
TypeTag
Type tag for fast dispatch without parsing OID. Maps to PostgreSQL type categories.

Functions§

read_batch
Deserialize a batch from FlexBuffers format.
read_event
Deserialize a single event from FlexBuffers format.
serialize_batch
Serialize a batch to FlexBuffers format.
serialize_event
Serialize a single event to FlexBuffers format.