mongo_crud_derive 0.1.0

A simple library to extract the mongoDB fetching process. Only for basic types.
Documentation
use proc_macro2::{Ident, TokenStream};
use quote::quote;

pub fn derive_delete(name: &Ident, collection_name: String, _partial_fields: Vec<Ident>) -> TokenStream {
    quote! {
        async fn delete(&self, ctx: &(impl mongo_crud_core::MongoContext + Sync)) -> bool {
                let db = mongo_crud_core::MongoContext::get_database(ctx).await;
                match db
                    .collection::<#name>(#collection_name)
                    .delete_one(mongodb::bson::doc! { "id": &self.id }, None)
                    .await
                {
                    Ok(_) => true,
                    Err(e) => {
                        log::error!("Failed to delete: {:?}", e);
                        false
                    }
                }
            }
    }
}