SqlParser

Struct SqlParser 

Source
pub struct SqlParser { /* private fields */ }
Expand description

SQL 解析器(基于 Tree-sitter)

Implementations§

Source§

impl SqlParser

Source

pub fn new() -> Self

创建 SQL 解析器

Source

pub fn parse(&mut self, sql: &str) -> ParseResult

解析 SQL 语句

Source

pub fn tokenize(&self, tree: &Tree, source: &str) -> Vec<Token>

提取所有 Token(参考 sqls 的 tokenizer)

Source

pub fn get_node_at_position<'a>( &self, tree: &'a Tree, position: Position, ) -> Option<Node<'a>>

获取指定位置的节点

Source

pub fn extract_tables(&self, tree: &Tree, source: &str) -> Vec<String>

提取查询中的表名

Source

pub fn is_in_from_context(&self, node: Node<'_>, source: &str) -> bool

检查节点是否在 FROM/JOIN 上下文中

Source

pub fn extract_columns(&self, tree: &Tree, source: &str) -> Vec<String>

提取查询中的列名

Source

pub fn is_in_column_context(&self, node: Node<'_>, source: &str) -> bool

检查节点是否在列上下文中(SELECT/WHERE/ORDER BY 等)

Source

pub fn node_text(&self, node: Node<'_>, source: &str) -> String

获取节点的文本内容

Source

pub fn node_range(&self, node: Node<'_>) -> Range

获取节点的范围

Source

pub fn analyze_completion_context( &self, node: Node<'_>, source: &str, _position: Position, ) -> CompletionContext

分析补全上下文 (Text-based heuristics for reliability) 分析补全上下文 (AST-based) Uses Tree-sitter AST node traversal for robust context detection

Source

pub fn get_table_name_for_column( &self, node: Node<'_>, source: &str, ) -> Option<String>

获取表名(用于 TableColumn 上下文) 如果光标在 table.column 的位置,返回表名

Source§

impl SqlParser

Source

pub fn extract_aliases( &self, _tree: &Tree, source: &str, ) -> HashMap<String, String>

提取表别名映射 (Alias -> Table Name) Uses text-based extraction for reliability

Source

pub fn extract_referenced_tables( &self, _tree: &Tree, source: &str, ) -> Vec<String>

提取SQL中引用的表名(从FROM和JOIN子句)

Source

pub fn node_to_ast_node(&self, node: Node<'_>, source: &str) -> AstNode

将 Tree-sitter Node 转换为 AstNode

Trait Implementations§

Source§

impl Default for SqlParser

Source§

fn default() -> Self

Returns the “default value” for a type. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more