Skip to main content

RuleContext

Struct RuleContext 

Source
pub struct RuleContext {
    pub sql: String,
    pub tokens: Vec<SqlToken>,
    pub statement_type: SqlStatementType,
    pub sql_upper: String,
}
Expand description

规则匹配上下文,封装 SQL 文本及其预计算信息

RuleEngine::check 在执行规则前构建,避免每条规则重复词法分析。

Fields§

§sql: String

原始 SQL 文本

§tokens: Vec<SqlToken>

词法分析后的令牌序列

§statement_type: SqlStatementType

语句类型

§sql_upper: String

SQL 全大写形式(便于关键字匹配,避免重复计算)

Implementations§

Source§

impl RuleContext

Source

pub fn from_sql(sql: &str) -> Self

从 SQL 文本构建上下文

Source

pub fn keyword_count(&self, keyword: &str) -> usize

统计指定关键字的个数(基于令牌序列,精确匹配关键字令牌)

Source

pub fn has_keyword(&self, keyword: &str) -> bool

判断是否包含指定关键字

Source

pub fn table_count(&self) -> usize

统计 FROM/JOIN/INTO/UPDATE 后的表标识符个数

Trait Implementations§

Source§

impl Clone for RuleContext

Source§

fn clone(&self) -> RuleContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for RuleContext

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.