Skip to main content

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/// This example is ignored because a complete custom executor belongs in an
14/// application crate that supplies its own concrete backend and error policy.
15///
16/// ```rust,ignore
17/// use type_bridge_server::{QueryExecutor, PipelineError};
18/// use std::pin::Pin;
19/// use std::future::Future;
20///
21/// struct MockExecutor;
22///
23/// impl QueryExecutor for MockExecutor {
24///     fn execute<'a>(&'a self, _database: &'a str, typeql: &'a str, _transaction_type: &'a str)
25///         -> Pin<Box<dyn Future<Output = Result<serde_json::Value, PipelineError>> + Send + 'a>>
26///     {
27///         Box::pin(async move {
28///             Ok(serde_json::json!([{"query": typeql}]))
29///         })
30///     }
31///     fn is_connected(&self) -> bool { true }
32/// }
33/// ```
34pub trait QueryExecutor: Send + Sync {
35    /// Execute a TypeQL string against the given database.
36    fn execute<'a>(
37        &'a self,
38        database: &'a str,
39        typeql: &'a str,
40        transaction_type: &'a str,
41    ) -> Pin<Box<dyn Future<Output = Result<serde_json::Value, PipelineError>> + Send + 'a>>;
42
43    /// Check if the backend connection is alive.
44    fn is_connected(&self) -> bool;
45}