#[cfg(any(
feature = "postgres",
feature = "redis",
feature = "mongodb",
feature = "neo4j",
feature = "firestore"
))]
use crate::{error::GraphError, state::Checkpoint};
#[cfg(feature = "postgres")]
pub mod postgres;
#[cfg(feature = "redis")]
pub mod redis;
#[cfg(feature = "mongodb")]
pub mod mongodb;
#[cfg(feature = "neo4j")]
pub mod neo4j;
#[cfg(feature = "firestore")]
pub mod firestore;
#[cfg(any(
feature = "postgres",
feature = "redis",
feature = "mongodb",
feature = "neo4j",
feature = "firestore"
))]
fn storage_error(backend: &str, error: impl std::fmt::Display) -> GraphError {
GraphError::CheckpointError(format!("{backend} checkpointer: {error}"))
}
#[cfg(any(
feature = "postgres",
feature = "redis",
feature = "mongodb",
feature = "neo4j",
feature = "firestore"
))]
fn encode(checkpoint: &Checkpoint) -> crate::error::Result<String> {
Ok(serde_json::to_string(checkpoint)?)
}
#[cfg(any(
feature = "postgres",
feature = "redis",
feature = "mongodb",
feature = "neo4j",
feature = "firestore"
))]
fn decode(backend: &str, text: &str) -> crate::error::Result<Checkpoint> {
serde_json::from_str(text)
.map_err(|error| storage_error(backend, format!("stored checkpoint is corrupt: {error}")))
}