dm_database_parser_sqllog/lib.rs
1//! # dm-database-parser-sqllog
2//!
3//! 一个高性能的达梦数据库 sqllog 日志解析库,提供零分配或低分配的记录切分与解析功能。
4//!
5//! ## 主要特点
6//!
7//! - **零分配解析**:基于时间戳的记录切分,使用流式 API 避免额外内存分配
8//! - **高效模式匹配**:使用双数组 Aho-Corasick(daachorse)进行高效模式匹配
9//! - **轻量级结构**:解析结果使用引用(`&str`),避免不必要的字符串复制
10//! - **灵活的 API**:提供批量解析、流式解析等多种使用方式
11//!
12//! ## 快速开始
13//!
14//! ```rust
15//! use dm_database_parser_sqllog::{split_by_ts_records_with_errors, parse_record, for_each_record};
16//!
17//! let log_text = r#"2025-08-12 10:57:09.562 (EP[0] sess:1 thrd:1 user:joe trxid:0 stmt:1 appname:MyApp) SELECT 1"#;
18//!
19//! // 将文本拆分为记录并获取前导错误
20//! let (records, errors) = split_by_ts_records_with_errors(log_text);
21//! println!("records: {}, leading errors: {}", records.len(), errors.len());
22//!
23//! // 流式处理每条记录(零分配)
24//! for_each_record(log_text, |rec| {
25//! let parsed = parse_record(rec);
26//! println!("ts={} body={}", parsed.ts, parsed.body);
27//! });
28//! ```
29//!
30//! ## 模块组织
31//!
32//! - [`parser`] - 核心解析功能,包括记录切分和解析
33//! - [`error`] - 错误类型定义
34//! - [`sqllog`] - Sqllog 结构体定义
35
36pub mod error;
37pub mod matcher;
38pub mod parser;
39pub mod sqllog;
40mod tools;
41
42// Re-export commonly used types and functions
43pub use error::ParseError;
44pub use parser::{
45 for_each_record, parse_all, parse_into, parse_record, parse_records_with,
46 split_by_ts_records_with_errors, split_into, ParsedRecord, RecordSplitter,
47};
48pub use sqllog::Sqllog;