My program uses rusqlite to create a database from another data source. The database builds several tables in the same way, so I thought I would make a reuse function:
fn download_generic<Inserter>(table_name: &str, connection: &mut rusqlite::Connection, inserter: &mut Inserter) -> Result<(), String> where Inserter: FnMut(&str, &json::JsonValue) -> () {}
inserter is a function that binds the correct values ββfrom a previously prepared statement and makes an insert.
I call it this way:
let mut insert_stmt = connection .prepare("insert or replace into categories values(?,?);") .unwrap(); download_generic("categories", &mut connection, &mut |uuid, jsonproperties| { insert_stmt.execute(&[&uuid, &jsonproperties["name"].as_str().unwrap_or("")]); });
However, I cannot pass &mut connection to download_generic because it is already borrowed by insert_stmt . Putting it into RefCell does not make sense, because I do not need extra time to complete this work.
I could try creating an insert_stmt generated by the lambda that you switch to download_generic , but then I get overwhelmed by the need to add timestamps everywhere, and still it seems unnatural.
source share