use oximod_core::feature::conn::client::set_global_client;
use oximod_core::feature::model::Model;
use oximod_macros::Model;
use mongodb::bson::{doc, oid::ObjectId};
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");
set_global_client(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,
active: bool,
}
User::clear().await?;
let user = User {
_id: None,
name: "User1".to_string(),
age: 28,
active: true,
};
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(())
}