pub async fn update(&self, key: impl fmt::Display, update: Update) -> Result<()> {
        let url = format!(
            "{}/{}/items/{}",
            self.url,
            self.base_name.as_ref().ok_or(Error::BaseNameNotPresent)?,
            key
        );

        self.client
            .patch(&url)
            .json(&update)
            .send()
            .await
            .map_err(|_| Error::RequestSendError)?
            .error_for_status()
            .map_err(|e| {
                if let Some(x) = e.status() {
                    if x == reqwest::StatusCode::NOT_FOUND {
                        return Error::KeyNonexistent;
                    } else if x == reqwest::StatusCode::BAD_REQUEST {
                        return Error::BadRequest;
                    }
                }
                Error::ServerError
            })?;

        Ok(())
    }
/// Updates an item only if an item with `key` exists.
///
/// # Arguments
///
/// * `update`: An `Update` struct.
///
/// # Errors
///
/// * [`Error::BaseNameNotPresent`](crate::Error::BaseNameNotPresent)
/// * [`Error::RequestSendError`](crate::Error::RequestSendError)
/// * [`Error::KeyNonexistent`](crate::Error::KeyNonexistent)
/// * [`Error::BadRequest`](crate::Error::BadRequest)
/// * [`Error::ServerError`](crate::Error::ServerError)
///
/// # Examples
///
/// ```no_run
/// use deta::{Deta, Update};
/// # #[tokio::main]
/// # async fn main() -> deta::Result<()> {
/// let deta = Deta::new()?;
///
/// let base = deta.base("main");
/// deta.update(
///     "user-a",
///     Update::new()
///             .set("profile.age", 33)
///         .set("profile.active", true)
///         .set("profile.email", "jimmy@deta.sh")
///         .increment("purchases", 2)
///         .append("likes", "ramen")
///         .prepend("likes", "noodles")
///         .delete("profile.hometown")
///         .delete("on_mobile"),
/// );
/// # Ok(())
/// # }
/// ```
Updates an item only if an item with `key` exists.
Updates an item only if an item with ` key ` exists .
pub async fn update(&self, key: impl fmt::Display, update: Update) -> Result<()> {
        let url = format!(
            "{}/{}/items/{}",
            self.url,
            self.base_name.as_ref().ok_or(Error::BaseNameNotPresent)?,
            key
        );
        self.client
            .patch(&url)
            .json(&update)
            .send()
            .await
            .map_err(|_| Error::RequestSendError)?
            .error_for_status()
            .map_err(|e| {
                if let Some(x) = e.status() {
                    if x == reqwest::StatusCode::NOT_FOUND {
                        return Error::KeyNonexistent;
                    } else if x == reqwest::StatusCode::BAD_REQUEST {
                        return Error::BadRequest;
                    }
                }
                Error::ServerError
            })?;
        Ok(())
    }
pub async fn update ( & self , key : impl fmt :: Display , update : Update ) -> Result < ( ) > { let url = format ! ( " " self url self base_name as_ref ( ) ok_or ( Error BaseNameNotPresent ) key ) ; self . client . patch ( & url ) . json ( & update ) . send ( ) . await . map_err ( | _ | Error :: RequestSendError ) ? . error_for_status ( ) . map_err ( | e | { if let Some ( x ) = e . status ( ) { if x == reqwest :: StatusCode :: NOT_FOUND { return Error :: KeyNonexistent ; } else if x == reqwest :: StatusCode :: BAD_REQUEST { return Error :: BadRequest ; } } Error :: ServerError } ) ? ; Ok ( ( ) ) }
Updates an item only if an item with `key` exists.
Updates an item only if an item with ` key ` exists .
&self
key
impl fmt::Display
update
Update
&self
key
impl fmt::Display
update
Update
errors
None
examples
```no_run
use deta::{Deta, Update}.
` ` ` no_run use deta :: { Deta Update } .
#[tokio::main]
None
async fn main() -> deta::result<()> {
let deta = Deta::new()?.

let base = deta.base("main");
deta.update(
"user-a",
Update::new()
.set("profile.age", 33)
.set("profile.active", true)
.set("profile.email", "jimmy@deta.sh")
.increment("purchases", 2)
.append("likes", "ramen")
.prepend("likes", "noodles")
.delete("profile.hometown")
.delete("on_mobile"),
).
let deta = Deta :: new () ? . let base = deta . base ( " main " ) ; deta . update ( " user - a " Update :: new () . set ( " profile . age " 33 ) . set ( " profile . active " true ) . set ( " profile . email " " jimmy@deta . sh " ) . increment ( " purchases " 2 ) . append ( " likes " " ramen " ) . prepend ( " likes " " noodles " ) . delete ( " profile . hometown " ) . delete ( " on_mobile " ) ) .
ok(())
None
}
None