tidaldb/tidal/examples/cli_embedding.rs
jordan 6fdaa1584b feat: complete M1 signal engine — m0p3 samples/docs, m1p5 TidalDb API, examples, and periodic checkpoint
- m0p3: CONTRIBUTING.md with run-samples checklist, all 4 examples
  (quickstart, cli_embedding, axum_embedding, actix_embedding), doc-test
  coverage for every public API surface
- m1p5: TidalDb public API — write_item, signal, read_decay_score,
  read_windowed_count, read_velocity; StorageBox enum routing memory vs
  fjall; WalSender/WalHandleWriter bridge; WAL replay on open
- Periodic checkpoint: 30s background thread for persistent+schema mode;
  FjallBackend::Clone (O(1), fjall::Keyspace is ref-counted); graceful
  shutdown via Arc<AtomicBool> + join before final checkpoint
- ROADMAP.md: M0 and M1 fully marked COMPLETE (341 tests passing)
- Milestone 2 planning scaffolding added under docs/planning/milestone-2/

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 22:45:10 -07:00

41 lines
1.3 KiB
Rust

//! tidalDB CLI embedding: open a persistent database and print status.
//!
//! Demonstrates:
//! - Opening a persistent `TidalDb` with an explicit data directory
//! - Printing build hash, uptime, and debug info
//! - Explicit `close()` before exit
//!
//! In a real CLI this data directory would come from a flag or config file.
//! Here we use a temporary directory so the example runs safely in CI.
//!
//! # Running
//!
//! ```bash
//! cargo run --example cli_embedding --manifest-path tidal/Cargo.toml
//! ```
fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt()
.with_env_filter("tidaldb=debug")
.init();
// Create a temporary directory to act as the data root.
// In a production CLI, replace this with the user-supplied path.
let tmp = tempfile::tempdir()?;
let data_dir = tmp.path();
let db = tidaldb::TidalDb::builder().with_data_dir(data_dir).open()?;
println!("build: {}", tidaldb::BUILD_HASH);
println!("data: {}", data_dir.display());
println!("uptime: {:.3}s", db.metrics().uptime_seconds());
println!("health: {:?}", db.health_check());
println!("debug: {db:?}");
// Explicit close — ensures any future WAL flush completes before exit.
db.close()?;
println!("shutdown complete.");
Ok(())
}