Record

Struct Record 

Source
pub struct Record {
    pub lines: Vec<String>,
}
Expand description

表示一条完整的日志记录(可能包含多行)

日志记录由一个起始行和零个或多个继续行组成。起始行包含时间戳和元数据, 继续行包含多行 SQL 语句的后续部分。

§示例

use dm_database_parser_sqllog::{Record, parse_records_from_string};

let log = r#"2025-08-12 10:57:09.548 (EP[0] sess:123 thrd:456 user:alice trxid:789 stmt:999 appname:app) SELECT *
FROM users
WHERE id = 1"#;

let records = parse_records_from_string(log);
assert_eq!(records.len(), 1);
assert!(records[0].has_continuation_lines());
assert_eq!(records[0].lines.len(), 3);

Fields§

§lines: Vec<String>

记录的所有行(第一行是起始行,后续行是继续行)

Implementations§

Source§

impl Record

Source

pub fn new(start_line: String) -> Self

创建新的记录

§参数
  • start_line - 记录的起始行
Source

pub fn add_line(&mut self, line: String)

添加继续行

§参数
  • line - 要添加的继续行
Source

pub fn start_line(&self) -> &str

获取起始行

§返回

返回记录的第一行(起始行)

Source

pub fn all_lines(&self) -> &[String]

获取所有行

§返回

返回包含所有行的切片

Source

pub fn full_content(&self) -> String

获取完整的记录内容(所有行拼接)

§返回

返回所有行用换行符拼接后的字符串

Source

pub fn has_continuation_lines(&self) -> bool

判断是否有继续行

§返回

如果记录包含多行(有继续行)返回 true,否则返回 false

Source

pub fn parse_to_sqllog(&self) -> Result<Sqllog, ParseError>

将 Record 解析为 Sqllog

§返回
  • Ok(Sqllog) - 解析成功
  • Err(ParseError) - 解析失败
§示例
use dm_database_parser_sqllog::{Record, parse_records_from_string};

let log = "2025-08-12 10:57:09.548 (EP[0] sess:123 thrd:456 user:alice trxid:789 stmt:999 appname:app) SELECT 1";
let records = parse_records_from_string(log);
let sqllog = records[0].parse_to_sqllog().unwrap();

assert_eq!(sqllog.meta.username, "alice");

Trait Implementations§

Source§

impl Clone for Record

Source§

fn clone(&self) -> Record

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Record

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Record

Source§

fn eq(&self, other: &Record) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Record

Auto Trait Implementations§

§

impl Freeze for Record

§

impl RefUnwindSafe for Record

§

impl Send for Record

§

impl Sync for Record

§

impl Unpin for Record

§

impl UnwindSafe for Record

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.