vorm 0.2.1

Wrapper library for MongoDB.
Documentation
use mongodb::bson::doc;
use oorandom::Rand32;
use serde::{Deserialize, Serialize};
use vorm;

/// Example data model.
#[derive(Clone, Debug, Deserialize, Serialize)]
struct Robot {
    id: String,
    team: u32,
    for_season: String,
    was_made_by_cool_people: bool,
}

#[tokio::test]
async fn bulk() {
    let records = vorm::Records::<Robot>::new(
        "robots",
        &vorm::get_db("mongodb://127.0.0.1:27017", "testing")
            .await
            .unwrap(),
    );
    let mut rng = Rand32::new(0);
    let seasons = vec![
        "Charged Up",
        "Rapid React",
        "Infinite Recharge",
        "Destination: Deep Space",
        "Power Up",
        "Steamworks",
        "Stronghold",
        "Recycle Rush",
    ];

    for i in 0..10000 {
        records
            .put(&Robot {
                id: format!("{i}"),
                team: rng.rand_range(1..9317),
                for_season: (*seasons
                    .get(rng.rand_range(0..(seasons.len() as u32)) as usize)
                    .unwrap())
                .to_owned(),
                was_made_by_cool_people: true,
            })
            .await
            .unwrap()
    }

    assert_eq!(records.count().await.unwrap(), 10000);
    assert_eq!(
        records
            .get_many(doc! {"was_made_by_cool_people": true})
            .await
            .unwrap()
            .len(),
        10000
    );

    let number_of_senior_robots = records
        .get_many(doc! {"for_season": "Recycle Rush"})
        .await
        .unwrap()
        .len();

    records
        .delete_many(doc! {"for_season": "Recycle Rush"})
        .await
        .unwrap();

    assert_eq!(
        records.count().await.unwrap(),
        10000 - number_of_senior_robots as u64
    );
}