type_bridge_server/executor.rs
1use std::future::Future;
2use std::pin::Pin;
3
4use crate::error::PipelineError;
5
6/// Backend-agnostic query execution trait.
7///
8/// Implement this trait to provide a custom database backend for the query pipeline.
9/// The built-in `TypeDBClient` (behind the `typedb` feature) implements this trait.
10///
11/// # Example
12///
13/// ```rust,ignore
14/// use type_bridge_server::{QueryExecutor, PipelineError};
15/// use std::pin::Pin;
16/// use std::future::Future;
17///
18/// struct MockExecutor;
19///
20/// impl QueryExecutor for MockExecutor {
21/// fn execute<'a>(&'a self, _database: &'a str, typeql: &'a str, _transaction_type: &'a str)
22/// -> Pin<Box<dyn Future<Output = Result<serde_json::Value, PipelineError>> + Send + 'a>>
23/// {
24/// Box::pin(async move {
25/// Ok(serde_json::json!([{"query": typeql}]))
26/// })
27/// }
28/// fn is_connected(&self) -> bool { true }
29/// }
30/// ```
31pub trait QueryExecutor: Send + Sync {
32 /// Execute a TypeQL string against the given database.
33 fn execute<'a>(
34 &'a self,
35 database: &'a str,
36 typeql: &'a str,
37 transaction_type: &'a str,
38 ) -> Pin<Box<dyn Future<Output = Result<serde_json::Value, PipelineError>> + Send + 'a>>;
39
40 /// Check if the backend connection is alive.
41 fn is_connected(&self) -> bool;
42}