argv-todo 0.1.0

A Vim-style terminal todo manager with nested tasks, priorities, search, and local SQLite storage
mod model;
mod ordering;
mod queries;
mod schema;
mod trees;

#[cfg(test)]
#[path = "../../tests/unit/db.rs"]
mod tests;

pub(crate) use model::{DEFAULT_PRIORITY, Priority, Todo};
pub(crate) use ordering::TaskMove;

use anyhow::{Context, Result};
use rusqlite::Connection;
use std::path::Path;

pub(crate) struct Database {
    connection: Connection,
}

impl Database {
    pub(crate) fn open(path: &Path) -> Result<Self> {
        if let Some(parent) = path.parent().filter(|p| !p.as_os_str().is_empty()) {
            std::fs::create_dir_all(parent)
                .with_context(|| format!("Could not create {}", parent.display()))?;
        }
        Self::initialize(Connection::open(path)?)
    }
}