I am trying to create a small app that uses an Sqlite database to store information, however I need the ability for the user to be able to set where the database resides from the front end. So initially there is no database set and the front end will just show the "New / Open Database" screen.
My problem is that I need to store the database connection (diesel::SqliteConnection) in the rust app state so that I can use it, however I can not figure out how to create the initial State object as I do not have an SqliteConnection at startup time, so I can not create the Mutex that wraps it.
In main.rs:
struct AppState {
count: Mutex<i64>,
conn: Mutex<SqliteConnection>,
db_location: Mutex<String>
}
fn main() {
let state = AppState {
count: Mutex::new(0),
conn: Mutex::new(Default::default()),
db_location: Mutex::new(String::from(""))
};
// Start the Application
let context = tauri::generate_context!();
let builder = tauri::Builder::default()
.manage(state)
.plugin(tauri_plugin_store::Builder::default().build())
.invoke_handler(tauri::generate_handler![
get_count,
update_count,
set_db_location,
... // bunch more handlers omitted for brevity
]);
let app = match builder.build(context) {
Err(e) => panic!("Can not build Tarui application: {e}"),
Ok(_f) => _f
};
However this fails to compile as the trait std::default::Default is not implemented for 'diesel::SqliteConnection'
Is it possible to set up a Mutex such that is does not have a value? I am loathe to randomly implement traits for SqliteConnection without understanding what I am messing with.