use std::fmt;
use crate::types::{BoltDict, BoltValue};
#[derive(Debug, Clone, PartialEq)]
pub enum ClientMessage {
Hello { extra: BoltDict },
Logon { auth: BoltDict },
Logoff,
Goodbye,
Reset,
Run {
query: String,
parameters: BoltDict,
extra: BoltDict,
},
Pull { extra: BoltDict },
Discard { extra: BoltDict },
Begin { extra: BoltDict },
Commit,
Rollback,
Route {
routing: BoltDict,
bookmarks: Vec<String>,
extra: BoltDict,
},
Telemetry { api: i64 },
}
impl fmt::Display for ClientMessage {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Hello { .. } => write!(f, "HELLO"),
Self::Logon { .. } => write!(f, "LOGON"),
Self::Logoff => write!(f, "LOGOFF"),
Self::Goodbye => write!(f, "GOODBYE"),
Self::Reset => write!(f, "RESET"),
Self::Run { query, .. } => write!(f, "RUN {query:?}"),
Self::Pull { .. } => write!(f, "PULL"),
Self::Discard { .. } => write!(f, "DISCARD"),
Self::Begin { .. } => write!(f, "BEGIN"),
Self::Commit => write!(f, "COMMIT"),
Self::Rollback => write!(f, "ROLLBACK"),
Self::Route { .. } => write!(f, "ROUTE"),
Self::Telemetry { api } => write!(f, "TELEMETRY({api})"),
}
}
}
impl ClientMessage {
pub fn pull_all() -> Self {
Self::Pull {
extra: BoltDict::from([("n".to_string(), BoltValue::Integer(-1))]),
}
}
pub fn pull_n(n: i64) -> Self {
Self::Pull {
extra: BoltDict::from([("n".to_string(), BoltValue::Integer(n))]),
}
}
pub fn discard_all() -> Self {
Self::Discard {
extra: BoltDict::from([("n".to_string(), BoltValue::Integer(-1))]),
}
}
}