adk_graph/checkpointers/
mod.rs1#[cfg(any(
18 feature = "postgres",
19 feature = "redis",
20 feature = "mongodb",
21 feature = "neo4j",
22 feature = "firestore"
23))]
24use crate::{error::GraphError, state::Checkpoint};
25
26#[cfg(feature = "postgres")]
27pub mod postgres;
28
29#[cfg(feature = "redis")]
30pub mod redis;
31
32#[cfg(feature = "mongodb")]
33pub mod mongodb;
34
35#[cfg(feature = "neo4j")]
36pub mod neo4j;
37
38#[cfg(feature = "firestore")]
39pub mod firestore;
40
41#[cfg(any(
42 feature = "postgres",
43 feature = "redis",
44 feature = "mongodb",
45 feature = "neo4j",
46 feature = "firestore"
47))]
48fn storage_error(backend: &str, error: impl std::fmt::Display) -> GraphError {
49 GraphError::CheckpointError(format!("{backend} checkpointer: {error}"))
50}
51
52#[cfg(any(
53 feature = "postgres",
54 feature = "redis",
55 feature = "mongodb",
56 feature = "neo4j",
57 feature = "firestore"
58))]
59fn encode(checkpoint: &Checkpoint) -> crate::error::Result<String> {
60 Ok(serde_json::to_string(checkpoint)?)
61}
62
63#[cfg(any(
64 feature = "postgres",
65 feature = "redis",
66 feature = "mongodb",
67 feature = "neo4j",
68 feature = "firestore"
69))]
70fn decode(backend: &str, text: &str) -> crate::error::Result<Checkpoint> {
71 serde_json::from_str(text)
72 .map_err(|error| storage_error(backend, format!("stored checkpoint is corrupt: {error}")))
73}