use crate::types::Value;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CdcOp {
Insert,
Update,
Delete,
Truncate,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TableRef {
pub schema: Option<String>,
pub name: String,
}
impl TableRef {
pub fn new(name: impl Into<String>) -> Self {
Self {
schema: None,
name: name.into(),
}
}
pub fn with_schema(schema: impl Into<String>, name: impl Into<String>) -> Self {
Self {
schema: Some(schema.into()),
name: name.into(),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct RowImage {
pub values: Vec<(String, Value)>,
}
impl RowImage {
pub fn new(values: Vec<(String, Value)>) -> Self {
Self { values }
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CdcCheckpoint(pub String);
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SourceMeta {
pub source: Option<String>,
pub checkpoint: Option<CdcCheckpoint>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CdcEvent {
pub meta: SourceMeta,
pub table: TableRef,
pub op: CdcOp,
pub before: Option<RowImage>,
pub after: Option<RowImage>,
}
pub trait CdcSource {
type Error: std::error::Error + Send + Sync + 'static;
fn next_batch(&mut self) -> Result<Option<Vec<CdcEvent>>, Self::Error>;
}