PoloDB: Error accessing database after insert: `RollbackNotInTransaction`
After upgrading to the new version, some places have given me the DatabaseOccupied error which is most likely why I had some corruption. In my db.rs file I have many functions that rely on each other that independently use the database. To fix opening the database over and over, I added code to pass the database from the top level function (get_db_info) all throughout the reliant functions. When inserting, it does not give me an error, but when I try to access the database using the same function again, it gives me an error. I have no idea what this error is but I hope I give a good idea of my problem and context within the code.
... is a placeholder for omitted information.
Here is the problematic code:
pub async fn get_db_info(...) -> ... {
let mut db = Database::open(database_location().as_str()).unwrap();
ftx_pub_key = get_dbinf_by_entry(&mut db, ...);
...
}
pub fn get_dbinf_by_entry(db: &mut polodb_core::Database, ...) -> ... {
let mut collection = db.collection("config").unwrap();
db_insert_config(db, ...)?
...
}
pub fn db_insert_config(db: &mut polodb_core::Database, ...) -> ... {
let mut document = mk_document! {
...
};
let inside = db_inside(db, document.as_mut());
let mut collection = db.collection("config").unwrap();
if inside {
//updates the database entry with new values
collection
.update(
Some(&mk_document! { "_key": ... }),
&mk_document! {
"$set": mk_document! {
"value": ...
}
},
)
.unwrap();
} else {
collection.insert(&mut document).unwrap();
}
...
}
pub fn db_inside(db: &mut polodb_core::Database, bruh: &mut polodb_bson::Document) -> bool {
let mut collection = db.collection("config").unwrap();
match collection.find_one(bruh).unwrap() {
Some(_val) => true,
None => false,
}
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18
I will probably refactor knowing those suggestions, thanks.