Function alfred_workflow::open_database_or_else
source · pub fn open_database_or_else<F>(name: &str, f: F) -> Result<Connection, Error>where
F: Fn(&Connection) -> Result<(), Error>,
Expand description
Opens or creates if not exists an SQLite database.
Arguments
name
- The name of the workflow, which will create a dedicated sub-directory for.vec!f
- A lazily evaluated function that is called when the database is first created.
Remarks
name
must be unique or it may conflict with other workflows.
Examples
use failure::Error;
use rusqlite::Connection;
use rusqlite::NO_PARAMS;
fn main() -> Result<(), Error> {
let conn = alfred_workflow::open_database_or_else("myworkflow", create_tables)?;
Ok(())
}
fn create_tables(conn: &Connection) -> Result<(), Error> {
conn.execute(
"CREATE TABLE IF NOT EXISTS config (
key TEXT NOT NULL PRIMARY KEY,
value TEXT NOT NULL
);",
NO_PARAMS,
)?;
Ok(())
}