Avoid error if DB folder does not exist

This commit is contained in:
dbr 2021-06-15 20:01:47 +10:00
parent 2f533d2f3a
commit e72b990ea2

View file

@ -77,9 +77,14 @@ pub struct SqliteStorage {
impl SqliteStorage {
pub fn new<P: AsRef<Path>>(directory: P) -> anyhow::Result<SqliteStorage> {
// Ensure parent folder exists
std::fs::create_dir_all(&directory)?;
// Open (or create) database
let db_file = directory.as_ref().join("taskchampion.sqlite3");
let con = Connection::open(db_file)?;
// Initialize database
let queries = vec![
"CREATE TABLE IF NOT EXISTS operations (id INTEGER PRIMARY KEY AUTOINCREMENT, data STRING);",
"CREATE TABLE IF NOT EXISTS sync_meta (key STRING PRIMARY KEY, value STRING);",