use super::Operator;
use async_trait::async_trait;
use serde_json::Value;
use anyhow::Result;
pub struct SqlOperator;
#[async_trait]
impl Operator for SqlOperator {
async fn execute(&self, config: &Value) -> Result<String> {
let _query = config
.get("query")
.and_then(|v| v.as_str())
.ok_or_else(|| anyhow::anyhow!("Missing 'query' field in SQL operator config"))?;
let _connection_string = config
.get("connection_string")
.and_then(|v| v.as_str())
.ok_or_else(|| anyhow::anyhow!("Missing 'connection_string' field in SQL operator config"))?;
Ok("SQL execution result".to_string())
}
fn name(&self) -> &'static str {
"sql"
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_sql_operator_missing_query() {
let config = serde_json::json!({
"connection_string": "sqlite::memory:"
});
let operator = SqlOperator;
let result = operator.execute(&config).await;
assert!(result.is_err());
}
}