use mongodb::bson::doc; use serde::{Deserialize, Serialize}; use vorm; /// Example data model. #[derive(Clone, Debug, Deserialize, Serialize)] struct Report { name: String, content: String, } #[tokio::test] async fn crud() { let records = vorm::Records::::new( "reports", &vorm::get_db("mongodb://127.0.0.1:27017", "testing") .await .unwrap(), ); let id = "Major Incident Report: December 14, 2017"; records .put(&Report { name: id.to_owned(), content: "Disconnect from WAN. The outside world is poisoned.".to_owned(), }) .await .unwrap(); assert!(records.count().await.unwrap() > 0); let data = records.get(doc! {"name": id}).await.unwrap().unwrap(); assert!(data.content.starts_with("Disconnect from WAN.")); records .update( doc! {"name": id}, &Report { name: id.to_owned(), content: "The men in suits are not your friends.".to_owned(), }, ) .await .unwrap(); assert!(records.exists(doc! {"name": id}).await.unwrap()); records.delete(doc! {"name": id}).await.unwrap(); assert_eq!(records.count().await.unwrap(), 0); }