chat_platform_native/
storage.rs

1use chat_core::error::ChatResult;
2use rusqlite::Connection;
3use std::path::PathBuf;
4
5/// Open a file-backed SQLite connection.
6///
7/// If `base_dir` is provided, the database is stored under that directory.
8/// Otherwise it is created in the current working directory.
9pub async fn open_storage(name: &str, base_dir: Option<&str>) -> ChatResult<Connection> {
10    let path = match base_dir {
11        Some(dir) => PathBuf::from(dir).join(format!("{}.db", name)),
12        None => PathBuf::from(format!("{}.db", name)),
13    };
14
15    let conn = Connection::open(&path)?;
16    Ok(conn)
17}