export.rs

 1use anyhow::Result;
 2use std::path::Path;
 3
 4use crate::db;
 5
 6pub fn run(root: &Path) -> Result<()> {
 7    let conn = db::open(root)?;
 8
 9    let mut stmt = conn.prepare(
10        "SELECT id, title, description, type, priority, status, parent, created, updated
11         FROM tasks ORDER BY id",
12    )?;
13
14    let tasks: Vec<db::Task> = stmt
15        .query_map([], db::row_to_task)?
16        .collect::<rusqlite::Result<_>>()?;
17
18    for t in &tasks {
19        let labels = db::load_labels(&conn, &t.id)?;
20        let blockers = db::load_blockers(&conn, &t.id)?;
21        let detail = db::TaskDetail {
22            task: db::Task {
23                id: t.id.clone(),
24                title: t.title.clone(),
25                description: t.description.clone(),
26                task_type: t.task_type.clone(),
27                priority: t.priority,
28                status: t.status.clone(),
29                parent: t.parent.clone(),
30                created: t.created.clone(),
31                updated: t.updated.clone(),
32            },
33            labels,
34            blockers,
35        };
36        println!("{}", serde_json::to_string(&detail)?);
37    }
38
39    Ok(())
40}