-
Notifications
You must be signed in to change notification settings - Fork 21
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
Read-write operations #27
Comments
This is definitely something that's supported! Without seeing more code, I'm not 100% sure what's going wrong, but here's a little test I wrote based on your code that seems to work fine. #[test]
fn test() -> Result<(), Error> {
let random_file = common::RandomFile::new();
let db = OpenOptions::new()
.strict_mode(true)
.open(&random_file.path)?;
let tx = db.tx(true)?;
let schema_index_kinds_bucket = tx.get_or_create_bucket("schema-index-kinds")?;
let schema_kinds_bucket = tx.get_or_create_bucket("schema-kinds")?;
let kindName = "kindName";
let kindId = 123_u8;
match schema_index_kinds_bucket.get(kindName) {
Some(_) => return Err(Error::IncompatibleValue),
None => {
schema_kinds_bucket.put(kindId.to_be_bytes(), kindName)?;
schema_index_kinds_bucket.put(kindName, kindId.to_be_bytes())?;
}
}
Ok(())
} |
I was messing with borrows and other rust concepts but it definitively works. Thanks for the example as it helped me to enhance some of my patterns :) Let me close the issue. Btw, I did some benchmarking and is crazy how fast this goes! The big limitations:
For instance, for hundred keys in a slow laptop:
On the other hand buckets are really performant to store edges where the predicate is the name of the bucket. The difference with other KVs forced me to check my code like 100 times looking for a mistake 😅 but it seem just to be way more performant! |
Hello! Noob question here as i'm using your project to learn rust.
Is there a way to read and write in the same transaction in order to do some conditional .put() ?
For instance adding one (key,value) only if the value is not present already
Example:
I'm opening a tx in the root,
then sending the buckets to some functions as references and inside that function i'm checking if a key exist, and if it exist, i'm throwing an error , and if not, i'm doing a .put()
The error I get, which makes sense if this is not compatible with read-write, is that the "schema_kinds_bucket" may not live long enough
The text was updated successfully, but these errors were encountered: