Skip to main content

rs_jsonnet/runtime/
db.rs

1//! Database handler for Jsonnet evaluator
2//!
3//! Provides std.ext.db functions for database operations:
4//! - std.ext.db.query: Execute GQL queries
5//! - std.ext.db.rewrite: Execute graph rewrite rules
6//! - std.ext.db.patch: Apply patches to the graph
7
8use crate::error::JsonnetError;
9use crate::value::JsonnetValue;
10
11/// Database handler trait for external database operations
12pub trait DatabaseHandler {
13    /// Execute a GQL query and return results
14    fn query(&self, query: &str, params: Option<&JsonnetValue>) -> Result<JsonnetValue, JsonnetError>;
15
16    /// Execute a graph rewrite rule
17    fn rewrite(&self, rule: &str, params: Option<&JsonnetValue>) -> Result<JsonnetValue, JsonnetError>;
18
19    /// Apply a patch to the graph
20    fn patch(&self, patch: &JsonnetValue) -> Result<JsonnetValue, JsonnetError>;
21}
22
23/// Default database handler that returns errors for unimplemented operations
24pub struct DefaultDatabaseHandler;
25
26impl DatabaseHandler for DefaultDatabaseHandler {
27    fn query(&self, _query: &str, _params: Option<&JsonnetValue>) -> Result<JsonnetValue, JsonnetError> {
28        Err(JsonnetError::runtime_error("Database operations not implemented"))
29    }
30
31    fn rewrite(&self, _rule: &str, _params: Option<&JsonnetValue>) -> Result<JsonnetValue, JsonnetError> {
32        Err(JsonnetError::runtime_error("Rewrite operations not implemented"))
33    }
34
35    fn patch(&self, _patch: &JsonnetValue) -> Result<JsonnetValue, JsonnetError> {
36        Err(JsonnetError::runtime_error("Patch operations not implemented"))
37    }
38}