audiot_core 0.2.0

Library that helps build the search database through the CLI, and eventually can be used to read data from that same database.
Documentation
use std::path::Path;

use log::{debug, info};
use rusqlite::Connection;

use crate::persistence::SqliteSetupArgs;

pub fn initialize_db(args: &SqliteSetupArgs) -> Result<Connection, String> {
    let conn = Connection::open(Path::new(&args.output)).unwrap();

    debug!("PRAGMA journal_mode = WAL; -- Write-Ahead Logging for better concurrency");
    conn.execute_batch("PRAGMA journal_mode = WAL;").unwrap(); // Write-Ahead Logging for better concurrency
    debug!("PRAGMA synchronous = NORMAL; -- Faster writes with reasonable safety");
    conn.execute("PRAGMA synchronous = NORMAL;", []).unwrap(); // Faster writes with reasonable safety
    debug!("PRAGMA cache_size = -2000000; -- Bigger cache size");
    conn.execute("PRAGMA cache_size = -2000000;", []).unwrap(); // Bigger cache size
    debug!("PRAGMA temp_store = MEMORY; -- Store any temp tables in memory");
    conn.execute("PRAGMA temp_store = MEMORY;", []).unwrap(); // Store any temp tables in memory
    debug!("PRAGMA auto_vacuum = FULL; -- Shrink databases with a delete");
    conn.execute("PRAGMA auto_vacuum = FULL;", []).unwrap(); // Shrink database with deletes

    for statement in args.create_table_sql().iter() {
        info!("Creating table {statement}");
        conn.execute(statement, []).unwrap();
    }

    Ok(conn)
}