Comments (4)
Hey @gdelazzari, thanks for checking out jammdb
!
You're absolutely right, it's an issue caused by the Transaction
getting dropped while the cursor still has a reference to it. I've added a lifetime to the Cursor
struct to prevent issues like this from happening again in the PR that is linked to this issue. Your code should look like this once you update to 0.3.1
:
use jammdb::{Cursor, Data, DB};
fn iterate<'a>(c: Cursor<'a>) -> Box<dyn Iterator<Item = String> + 'a> {
Box::new(
c.filter_map(|item| match item {
Data::Bucket(_) => None,
Data::KeyValue(kv) => Some(kv),
})
.map(|kv| String::from_utf8(kv.value().to_vec()).unwrap()),
)
}
fn main() {
let mut db = DB::open("my-database.db").unwrap();
let mut tx = db.tx(false).unwrap();
let b = tx.get_bucket("names").unwrap();
for surname in iterate(b.cursor()) {
println!("{}", surname);
}
}
Hope that fixes your problem!
from jammdb.
Many thanks for the responsiveness! I will try to adapt my code, it won't be as easy as the change you made because I'm actually returning a boxed iterator from a struct method (where the struct owns the DB). I guess I'll have to implement a custom iterator which holds the transaction, the bucket and the cursor. I'll figure that out.
Do you think I can safely store a Transaction in a boxed struct? Or there might be a similar problem where the Transaction is not tied to the lifetime of the DB?
from jammdb.
The Transaction
is already attached to the lifetime of the DB
so you should be good there! And a Bucket
is likewise attached to the lifetime of the Transaction
. So your idea of making a custom iterator should work fine! If you want to have several of those structs, each with their own transactions, just be sure to .clone()
the DB each time!
from jammdb.
I've also just published v0.3.1
to fix your issue!
from jammdb.
Related Issues (15)
- panicked at 'assertion failed: self.meta.root_page == page_id || self.page_parents.contains_key(&page_id)' HOT 12
- Power outage tolerance HOT 5
- database Design HOT 5
- Allow users to specify mmap and file flags on Unix
- Simple put-and-get example uses writable=true for get HOT 1
- Describe complexity bounds HOT 1
- Async version HOT 2
- Misaligned ptr HOT 3
- Read-write operations HOT 2
- API safety and soundness HOT 2
- the trait `ResponseError` is not implemented for `jammdb::Error` HOT 6
- [E0596] cannot borrow data in an Arc as mutable. HOT 4
- [question] Is there way to list all the buckets HOT 5
- panicked at 'attempt to subtract with overflow' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jammdb.