MySQL mysqldump stream processor / mutator in Rust
This crate allows to parse and the insert values of a mysqldump file
and change them on the fly. Its intended usage is to anonymize a
mysqldump backup in order to safely allow to be shared between
developers.
use mysqldump_mutator::{InsertContext, Parser, SQLContextType, Token};
# use std::fs::File;
# use std::io::{self, BufReader};
# fn main() -> io::Result<()> {
# let file: String = std::env::args().collect::<Vec<String>>()[1].clone();
let _ = Parser::parse_mysqldump(
BufReader::new(File::open(&file)?),
|context, token| match context {
SQLContextType::Insert(InsertContext::Value((table_name, column_index)))
if table_name == "users" && column_index == &3 =>
{
Token::new(&"[REDACTED]".to_string(), Some('\''))
}
SQLContextType::ColumnDefinition((_table_name, _column_name, _column_index)) => {
# token
}
_ => token, },
|tokens| {
for token in tokens {
print!("{}", token)
}
},
);
# Ok(())
# }