task_cli/configs/
sqlite.rs

1// Copyright 2018 Mathew Robinson <chasinglogic@gmail.com>. All rights reserved. Use of this source code is
2// governed by the Apache-2.0 license that can be found in the LICENSE file.
3
4
5use std::path::PathBuf;
6use std::process::exit;
7use taskforge::list::SQLiteList;
8
9#[derive(Deserialize, Clone)]
10pub struct SqliteConfig {
11    pub filename: PathBuf,
12    pub create_tables: Option<bool>,
13}
14
15impl SqliteConfig {
16    pub fn list(mut self) -> Box<SQLiteList> {
17        if !self.filename.exists() {
18            self.create_tables = Some(true);
19        }
20
21        let mut list = SQLiteList::new(&self.filename);
22        if self.create_tables.is_some() && self.create_tables.unwrap() {
23            if let Err(e) = list.create_tables() {
24                println!("Unable to create tables in SQLite: {}", e);
25                exit(1);
26            }
27        }
28
29        Box::new(list)
30    }
31}