sz_orm_model/executor.rs
1//! 执行器 trait(模型层与执行层的契约)
2//!
3//! 为避免 sz-orm-model 反向依赖 sz-orm-pool,定义此最小执行器 trait。
4//! `sz-orm-pool` 中的 `Connection` trait 应实现此 trait,
5//! 使 `Model` 的关系加载方法可以接受任意 `Executor` 实现。
6
7use std::collections::HashMap;
8use std::future::Future;
9use std::pin::Pin;
10
11use crate::error::DbError;
12use crate::value::Value;
13
14/// 查询结果行:`Vec<HashMap<列名, 值>>`
15pub type QueryRows = Vec<HashMap<String, Value>>;
16
17/// 最小执行器 trait
18///
19/// 抽象了"执行 SQL 并返回结果行"的能力。
20/// `sz-orm-pool::Connection` 和测试中的 Mock 连接都应实现此 trait。
21pub trait Executor {
22 /// 执行查询 SQL,返回结果行
23 fn execute_query<'a>(
24 &'a mut self,
25 sql: &'a str,
26 ) -> Pin<Box<dyn Future<Output = Result<QueryRows, DbError>> + Send + 'a>>;
27}