I am not a professional developer, I am just a noob trying to learn rust.
I am writing an API using actix-web, and almost all functions are async. I want to make use of an SQLite database, and so I use the async-sqlite crate to handle that. This crate is based on the rusqlite crate, but is supposed to help with the async aspects of things.
This works fine as long as I am writing to the database, or making queries resulting in a single row response. However, in order to query for more than one row I have to prepare a statement first, but when I do this I get four errors complaining about things cannot be shared between threads safely.
Ex.
let result = match sql_pool.conn(move|conn| {
| ^^^^ `RefCell<hashlink::lru_cache::LruCache<Arc<str>, rusqlite::raw_statement::RawStatement>>` cannot be shared between threads safely
My code looks like this
let result = match sql_pool.conn(move|conn| {
let mut stmt = conn.prepare("SELECT attribute WHERE resource = :resource).unwrap();
let rows = stmt.query_map(&[(":resource", "https://test.com")], |row| row.get(0));
let mut attributes = Vec::new();
for attr in rows {
attributes.push(attr);
}
Ok(attributes)
}).await {
Ok(attrib) => Ok(attrib),
Err(e) => return Err("There was an error".to_string())
};
Is there another way that I am missing? Will I have to change to another crate for SQLite, and in that case: what will work?
Thank you in advance.