[][src]Crate mysqldump_mutator

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};

let _ = Parser::parse_mysqldump(
    BufReader::new(File::open(&file)?),
    |context, token| match context {
        // You can get the origial token content with token.to_string()
        // Check the Token struct methods
        SQLContextType::Insert(InsertContext::Value((table_name, column_index)))
            if table_name == "users" && column_index == &3 =>
        {
            // You can change the value of the column in an inser.  
            // Columns are identifies by index.  
            Token::new(&"[REDACTED]".to_string(), Some('\''))
        }
        SQLContextType::ColumnDefinition((_table_name, _column_name, _column_index)) => {
            // Here you can take note of what index is each column in each table.
        }
        _ => token, // Or just return the original token
    },
    |tokens| {
        for token in tokens {
            // Token has implemented the Display trait.
            // Given that no token was replaced, this would generate an output.  
            // byte-by-byte equal to the input.  
            print!("{}", token)
        }
    },
);

Structs

Parser

SQL Parser

Enums

InsertContext
SQLContextType

Context given to the value handler clousure. This indicates where in the query is the parser.

Token

SQL Token enumeration