use tegdb::Database;
fn main() -> tegdb::Result<()> {
println!("=== TegDB Simple Usage Example ===\n");
let db_path = std::env::temp_dir().join("simple_usage.teg");
let _ = std::fs::remove_file(&db_path);
println!("1. Opening database...");
let mut db = Database::open(format!("file://{}", db_path.display()))?;
println!(" ✓ Database opened with native binary format");
println!("2. Creating table...");
db.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT(32), score REAL)")?;
println!(" ✓ Table created");
println!("3. Inserting data...");
db.execute("INSERT INTO users (id, name, score) VALUES (1, 'Alice', 95.5)")?;
db.execute("INSERT INTO users (id, name, score) VALUES (2, 'Bob', 87.2)")?;
db.execute("INSERT INTO users (id, name, score) VALUES (3, 'Carol', 92.8)")?;
println!(" ✓ Data inserted");
println!("4. Querying data...");
let results = db
.query("SELECT name, score FROM users WHERE score > 90.0")
.unwrap();
println!(" Users with score > 90:");
for row in results.rows() {
if let (Some(name), Some(score)) = (row.first(), row.get(1)) {
println!(" {name:?} - {score:?}");
}
}
println!("5. Updating data...");
let affected = db.execute("UPDATE users SET score = 89.2 WHERE name = 'Bob'")?;
println!(" ✓ Updated {affected} row");
println!("6. Final results...");
let final_results = db.query("SELECT name, score FROM users").unwrap();
println!(" All users:");
for row in final_results.rows() {
if let (Some(name), Some(score)) = (row.first(), row.get(1)) {
println!(" {name:?} - {score:?}");
}
}
println!("\n🎉 All operations completed successfully!");
println!("💡 Notice how simple the API is:");
println!(" - Just `Database::open()` - no configuration needed");
println!(" - Native binary format used automatically");
println!(" - SQLite-like interface for familiar usage");
let _ = std::fs::remove_file(&db_path);
Ok(())
}