#![forbid(unsafe_code)]
use std::process::ExitCode;
use obj::{Db, Document};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
struct SmokeUser {
email: String,
handle: String,
}
impl Document for SmokeUser {
const COLLECTION: &'static str = "smoke_users";
const VERSION: u32 = 1;
}
fn main() -> ExitCode {
let mut args = std::env::args_os().skip(1);
let Some(path) = args.next() else {
eprintln!("usage: seed_for_cli <path>");
return ExitCode::from(2);
};
let db = match Db::open(&path) {
Ok(d) => d,
Err(e) => {
eprintln!("seed_for_cli: open failed: {e}");
return ExitCode::from(2);
}
};
for i in 0..8u32 {
let user = SmokeUser {
email: format!("user{i}@example.com"),
handle: format!("u{i}"),
};
if let Err(e) = db.insert(user) {
eprintln!("seed_for_cli: insert failed: {e}");
return ExitCode::from(2);
}
}
println!("seed_for_cli: 8 docs inserted into smoke_users");
ExitCode::SUCCESS
}