use mongodb::bson::{doc, oid::ObjectId};
use oximod::{Model, OxiClient};
use serde::{Deserialize, Serialize};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv::dotenv().ok();
let mongodb_uri = std::env::var("MONGODB_URI")
.expect("MONGODB_URI must be set in your .env file or environment");
OxiClient::init_global(mongodb_uri).await?;
#[derive(Debug, Serialize, Deserialize, Model)]
#[db("basic_usage_db")]
#[collection("users")]
struct User {
#[serde(skip_serializing_if = "Option::is_none")]
_id: Option<ObjectId>,
name: String,
age: i32,
#[default(true)]
active: bool,
}
User::clear().await?;
let user = User::new().name("User1".to_string()).age(28);
let id = user.save().await?;
println!("✅ Saved user with _id: {}", id);
let count = User::count(doc! {}).await?;
println!("📊 There are {} user(s) in the collection.", count);
Ok(())
}