iter_sqllogs_from_file

Function iter_sqllogs_from_file 

Source
pub fn iter_sqllogs_from_file<P>(
    path: P,
) -> Result<SqllogParser<BufReader<File>>, ParseError>
where P: AsRef<Path>,
Expand description

从文件读取并返回 Sqllog 迭代器(流式处理)

这是一个便捷函数,从文件读取日志并返回 SqllogParser 迭代器。 使用迭代器可以避免一次性加载所有数据到内存,适合处理大文件。

§参数

  • path - 日志文件路径

§返回

  • Ok(SqllogParser<BufReader<File>>) - Sqllog 迭代器
  • Err(ParseError) - 文件打开错误

§示例

use dm_database_parser_sqllog::iter_sqllogs_from_file;

let parser = iter_sqllogs_from_file("sqllog.txt")?;

let mut success_count = 0;
let mut error_count = 0;

for result in parser {
    match result {
        Ok(sqllog) => {
            success_count += 1;
            println!("用户: {}, SQL: {}", sqllog.meta.username, sqllog.body);
        }
        Err(err) => {
            error_count += 1;
            eprintln!("解析错误: {}", err);
        }
    }
}

println!("成功: {} 条, 错误: {} 个", success_count, error_count);