Skip to main content

Nl2SqlEngine

Trait Nl2SqlEngine 

Source
pub trait Nl2SqlEngine: Send + Sync {
    // Required methods
    fn generate<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        nl_query: &'life1 str,
        schema: &'life2 SchemaContext,
    ) -> Pin<Box<dyn Future<Output = Result<SqlQuery, Nl2SqlError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn validate<'life0, 'life1, 'async_trait>(
        &'life0 self,
        query: &'life1 SqlQuery,
    ) -> Pin<Box<dyn Future<Output = Result<bool, Nl2SqlError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

NL→SQL 引擎 trait

所有 NL→SQL 实现必须实现此 trait,以保证一致的接口。

Required Methods§

Source

fn generate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, nl_query: &'life1 str, schema: &'life2 SchemaContext, ) -> Pin<Box<dyn Future<Output = Result<SqlQuery, Nl2SqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

将自然语言查询转换为 SQL

§参数
  • nl_query: 自然语言查询(如 “show all users where age > 25”)
  • schema: 数据库 schema 上下文
§返回值
  • Ok(SqlQuery): 生成的 SQL 查询
  • Err(Nl2SqlError): 转换失败
Source

fn validate<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 SqlQuery, ) -> Pin<Box<dyn Future<Output = Result<bool, Nl2SqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

验证生成的 SQL 是否安全可用

执行以下检查:

  • 只允许 SELECT 语句
  • 无 SQL 注入风险

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§