Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the api of transaction apply_batch #1013

Closed
Erk- opened this issue Mar 10, 2020 · 1 comment
Closed

Change the api of transaction apply_batch #1013

Erk- opened this issue Mar 10, 2020 · 1 comment

Comments

@Erk-
Copy link
Contributor

Erk- commented Mar 10, 2020

I propose to change the api of the apply_batch method in transactions from:

pub fn apply_batch(
    &self,
    batch: Batch,
) -> UnabortableTransactionResult<()>

to

pub fn apply_batch(
    &self,
    batch: &Batch,
) -> UnabortableTransactionResult<()>

This will then mean that it will be possible to write code like this:

let db = config.open().unwrap();

let t1 = db.open_tree(b"1")?;

let mut b1 = Batch::default();
b1.insert(b"k1", b"v1");
b1.insert(b"k2", b"v2");

t1.transaction(|tree| {
    tree.apply_batch(&b1)?;
    Ok(())
})?;
@spacejam
Copy link
Owner

I like it! Thanks for improving this API :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants