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_insert(_name: &Ident, collection_name: String, _partial_fields: Vec<Ident>) -> TokenStream {
    quote! {
        async fn insert(&self, ctx: &(impl mongo_crud_core::MongoContext + Sync)) -> bool {
            let db = mongo_crud_core::MongoContext::get_database(ctx).await;
            match db
                .collection(#collection_name)
                .insert_one(mongodb::bson::to_document(self).unwrap(), None)
                .await
            {
                Ok(_) => true,
                Err(e) => {
                    log::error!("Failed to insert: {:?}", e);
                    false
                }
            }
        }
    }
}