Skip to main content

SqlParser

Struct SqlParser 

Source
pub struct SqlParser;
Expand description

SQL 解析器(对标 Java JSqlParser + CCJSqlParserUtil)。

使用正则表达式进行轻量级 SQL 解析。 生产版本可替换为完整的 SQL parser(如 sqlparser-rs crate)。

Implementations§

Source§

impl SqlParser

Source

pub fn parse(sql: &str) -> ParsedSql

解析 SQL 语句(对标 JSqlParser.parse(sql))。

Source

pub fn get_count_sql(sql: &str) -> String

获取 COUNT SQL(对标 ISqlParser.getOriginalCountSql())。

将 SELECT ... FROM ... 转为 SELECT COUNT(*) FROM ...。 如果包含 GROUP BY,则包装为子查询。

Source

pub fn replace_select_star(sql: &str, columns: &[&str]) -> String

优化 SELECT *(对标 SelectItemVisitorAdapter + 列裁剪)。

如果 SQL 是 SELECT *,可以替换为具体列名。

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.