Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889use turso::Builder;use turso::Connection;
struct Chore { name: String, periodic_time: i16, last_completed: String,}
#[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> { let db = Builder::new_local("app.db").build().await?; let conn = db.connect()?;
init_db(conn.clone()).await?;
// let mut rows = conn.query("SELECT * FROM chores", ()).await?; // while let Some(row) = rows.next().await? { // let id: i64 = row.get(0)?; // let name: String = row.get(1)?; // let periodic_time: i32 = row.get(2)?; // let last_completed: String = row.get(3)?; // println!("Chore: {} {} {} {}", id, name, periodic_time, last_completed); // }
Ok(())}
async fn init_db(conn: Connection) -> Result<(), Box<dyn std::error::Error>> { conn.execute( "CREATE TABLE IF NOT EXISTS chores ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL UNIQUE, periodic_time smallint NOT NULL, last_completed date NOT NULL )", (), ).await?;
let chores = vec![ Chore { name: String::from("Sweep/Vacuum"), periodic_time: 1, last_completed: String::from("2026-06-01") }, Chore { name: String::from("Clean Bathroom"), periodic_time: 1, last_completed: String::from("2026-06-01") }, Chore { name: String::from("Wipe Counters"), periodic_time: 1, last_completed: String::from("2026-06-01") }, Chore { name: String::from("P1 Laundry"), periodic_time: 1, last_completed: String::from("2026-06-01") }, Chore { name: String::from("P2 Laundry"), periodic_time: 1, last_completed: String::from("2026-06-01") }, Chore { name: String::from("Bed Laundry"), periodic_time: 1, last_completed: String::from("2026-06-01") }, Chore { name: String::from("Trash/Recycle"), periodic_time: 1, last_completed: String::from("2026-06-01") }, ];
for chore in &chores { conn.execute("INSERT INTO chores (name, periodic_time, last_completed) VALUES (?, ?, ?) ON CONFLICT(name) DO NOTHING",( chore.name.clone(), chore.periodic_time, chore.last_completed.clone(), )).await?; }
Ok(())}