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

Add ability to iterate over all Lists in the PickleDB #32

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

landhb
Copy link
Contributor

@landhb landhb commented Jan 23, 2023

This is definitely a breaking change, and would require a major version bump, since it changes a few of the existing types and methods. But I think this might be a more intuitive naming scheme for the list iterators.

The updated types are:

PickleDbListIterator: Iterates over all lists in the DB
PickleDbListItemIterator: Iterates over items in a specific list
PickleDbListItem: Item yielded from a list

Updates in this PR to make these changes:

  • The old PickleDb::liter() is now named PickleDb::liter_get() to obtain an iterator over a specific list.
  • The old PickleDbListIterator is now named PickleDbListItemIterator since it iterates over items in a list.
  • Changes PickleDb::liter() to produce an iterator over all lists in the db (the new PickleDbListIterator)
  • Introduces a new PickleDbListIterator that yields an iterator per list PickleDbListItemIterator
let mut db = pickledb::PickleDb::new_bin("1.db", pickledb::PickleDbDumpPolicy::AutoDump);

// Create a new list
db.lcreate("list1").unwrap()
    .lextend(&vec![1,2,3,4]);

// Create another one
db.lcreate("list2").unwrap()
    .lextend(&vec![5,6,7,8]);

// Iterate over all lists
for list in db.liter() {
    println!("Iterating over list: {:?}", list.name());
    for item in list {
        println!("Current item is: {}", item.get_item::<i32>().unwrap());
    }
}

@seladb
Copy link
Owner

seladb commented Jan 24, 2023

@landhb thank you for working on this!

I'm thinking if there's a way to make it backward compatible - maybe preserve the old list iterator (and mark it as deprecated) and introduce new iterators?

This way users can enjoy this new feature and at the same time it won't break anything for existing usage. Let me know what you think

@landhb
Copy link
Contributor Author

landhb commented Feb 25, 2023

Hey @seladb sorry for the late response. I'll see if I can feature gate it and add deprecation warnings.

@landhb
Copy link
Contributor Author

landhb commented Mar 20, 2023

@seladb Finally got some time to come back to this. I've added the deprecation warning, and by default all old code using liter() will continue to compile and work as before. Just with the added warning:

$ cargo run --example lists
   Compiling pickledb v0.5.2 (/mnt/archive/Documents/Projects/pickledb-rs)
warning: use of deprecated associated function `pickledb::PickleDb::liter`: Please switch to `pickledb::PickleDb::liter_get`
   --> examples/lists/src/main.rs:110:25
    |
110 |     for item_iter in db.liter("list2") {
    |                         ^^^^^
    |
    = note: `#[warn(deprecated)]` on by default

warning: `pickledb` (example "lists") generated 1 warning

To use the newer version of liter users will need to opt-in to the list-iterator feature.

@seladb
Copy link
Owner

seladb commented Mar 25, 2023

Thank you @landhb ! I'm a little bit busy right now but I'll take a look soon

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

Successfully merging this pull request may close these issues.

2 participants