use redb::Database;
use redb::DatabaseError;
use std::path::PathBuf;

mod bincode;
pub mod db_models;

pub const DB_FILE: &str = "datastore/private/ascend.redb";

#[tracing::instrument(err)]
pub fn create() -> Result<Database, DatabaseError> {
    let file = PathBuf::from(DB_FILE);

    // Create parent dirs
    if let Some(parent_dir) = file.parent() {
        std::fs::create_dir_all(parent_dir)?;
    }

    let db = Database::create(file)?;
    Ok(db)
}
