mysqlbinlog_network/mysql_binlog/
table_map.rs

1use std::collections::BTreeMap;
2
3use crate::mysql_binlog::column_types::ColumnType;
4
5#[derive(Debug)]
6/// Opaque reference to a table map, intended to be consumed by [`Event`]
7pub struct SingleTableMap {
8    pub(crate) schema_name: String,
9    pub(crate) table_name: String,
10    pub(crate) columns: Vec<ColumnType>,
11}
12
13/// A MySQL binary log includes Table Map events; the first time a table is referenced in a given
14/// binlog, a TME will be emitted describing the fields of that table and assigning them to a
15/// binlog-unique identifier. The TableMap object is used to keep track of that mapping.
16pub struct TableMap {
17    inner: BTreeMap<u64, SingleTableMap>,
18}
19
20impl TableMap {
21    pub fn new() -> Self {
22        TableMap {
23            inner: BTreeMap::new(),
24        }
25    }
26
27    pub fn handle(
28        &mut self,
29        table_id: u64,
30        schema_name: String,
31        table_name: String,
32        columns: Vec<ColumnType>,
33    ) {
34        let map = SingleTableMap {
35            schema_name,
36            table_name,
37            columns,
38        };
39        self.inner.insert(table_id, map);
40    }
41
42    pub fn get(&self, table_id: u64) -> Option<&SingleTableMap> {
43        self.inner.get(&table_id)
44    }
45}