#[macro_export]
macro_rules! auto_method {
    ($name:ident($selector_t:ty as i64)@$select_fn:ident -> $query:literal --name=$name_:literal --returns=$returns_:tt --cache-key-tmpl=$cache_key_tmpl:literal) => {
        pub async fn $name(&self, selector: $selector_t) -> Result<$returns_> {
            if let Some(cached) = self
                .0
                .1
                .get(format!($cache_key_tmpl, selector.to_string()))
                .await
            {
                match serde_json::from_str(&cached) {
                    Ok(x) => return Ok(x),
                    Err(_) => {
                        self.0
                            .1
                            .remove(format!($cache_key_tmpl, selector.to_string()))
                            .await
                    }
                };
            }

            let conn = match self.0.connect().await {
                Ok(c) => c,
                Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
            };

            let res = oiseau::query_row!(&conn, $query, &[&(selector as i64)], |x| {
                Ok(Self::$select_fn(x))
            });

            if res.is_err() {
                return Err(Error::GeneralNotFound($name_.to_string()));
            }

            let x = res.unwrap();
            self.0
                .1
                .set(
                    format!($cache_key_tmpl, selector),
                    serde_json::to_string(&x).unwrap(),
                )
                .await;

            Ok(x)
        }
    };

    ($name:ident($x:ty) -> $query:literal --serde --cache-key-tmpl=$cache_key_tmpl:literal) => {
        pub async fn $name(&self, id: usize, x: $x) -> Result<()> {
            let conn = match self.0.connect().await {
                Ok(c) => c,
                Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
            };

            let res = execute!(
                &conn,
                $query,
                params![&serde_json::to_string(&x).unwrap(), &(id as i64)]
            );

            if let Err(e) = res {
                return Err(Error::DatabaseError(e.to_string()));
            }

            self.0.1.remove(format!($cache_key_tmpl, id)).await;

            Ok(())
        }
    };
}
