use crate::types::UpdateOp;
#[derive(Debug, Clone, Default)]
pub struct UpdateBuilder {
ops: Vec<UpdateOp>,
}
impl UpdateBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn set(mut self, path: impl Into<String>, value: impl Into<serde_json::Value>) -> Self {
self.ops.push(UpdateOp::set(path.into(), value.into()));
self
}
pub fn increment(mut self, path: impl Into<String>, by: i64) -> Self {
self.ops.push(UpdateOp::increment(path.into(), by));
self
}
pub fn decrement(mut self, path: impl Into<String>, by: i64) -> Self {
self.ops.push(UpdateOp::decrement(path.into(), by));
self
}
pub fn remove(mut self, path: impl Into<String>) -> Self {
self.ops.push(UpdateOp::remove(path.into()));
self
}
pub fn merge(mut self, value: impl Into<serde_json::Value>) -> Self {
self.ops.push(UpdateOp::merge(value.into()));
self
}
pub fn build(self) -> Vec<UpdateOp> {
self.ops
}
}