This repository has been archived by the owner on Aug 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): add
mvcc
and scan_read
to demonstrate scan and tr…
…ansaction functions respectively
- Loading branch information
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use bytes::Bytes; | ||
use tempfile::TempDir; | ||
use kip_db::kernel::lsm::storage::{Config, KipStorage}; | ||
use kip_db::kernel::Storage; | ||
use kip_db::KernelError; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), KernelError> { | ||
let temp_dir = TempDir::new().expect("unable to create temporary working directory"); | ||
let config = Config::new(temp_dir.into_path()).enable_level_0_memorization(); | ||
let kip_storage = KipStorage::open_with_config(config).await?; | ||
|
||
println!("New Transaction"); | ||
let mut tx = kip_storage.new_transaction().await; | ||
|
||
println!("Set KeyValue after the transaction -> (key_1, value_1)"); | ||
kip_storage | ||
.set(b"key_1", Bytes::copy_from_slice(b"value_1")) | ||
.await?; | ||
|
||
println!("Read key_1 on the transaction: {:?}", tx.get(b"key_1")?); | ||
|
||
println!("Set KeyValue on the transaction -> (key_2, value_2)"); | ||
tx.set(b"key_2", Bytes::copy_from_slice(b"value_2")); | ||
|
||
println!( | ||
"Read key_2 on the transaction: {:?}", | ||
tx.get(b"key_2")? | ||
); | ||
|
||
println!( | ||
"Read key_2 on the storage: {:?}", | ||
kip_storage.get(b"key_2").await? | ||
); | ||
|
||
println!("Commit this transaction"); | ||
tx.commit().await?; | ||
|
||
println!( | ||
"Read key_2 on the storage again!: {:?}", | ||
kip_storage.get(b"key_2").await? | ||
); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::collections::Bound; | ||
use bytes::Bytes; | ||
use tempfile::TempDir; | ||
use kip_db::kernel::lsm::storage::{Config, KipStorage}; | ||
use kip_db::kernel::Storage; | ||
use kip_db::KernelError; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), KernelError> { | ||
let temp_dir = TempDir::new().expect("unable to create temporary working directory"); | ||
let config = Config::new(temp_dir.into_path()).enable_level_0_memorization(); | ||
let kip_storage = KipStorage::open_with_config(config).await?; | ||
|
||
println!("Set KeyValue -> (key_1, value_1)"); | ||
kip_storage | ||
.set(b"key_1", Bytes::copy_from_slice(b"value_1")) | ||
.await?; | ||
println!("Set KeyValue -> (key_2, value_2)"); | ||
kip_storage | ||
.set(b"key_2", Bytes::copy_from_slice(b"value_2")) | ||
.await?; | ||
println!("Set KeyValue -> (key_3, value_3)"); | ||
kip_storage | ||
.set(b"key_3", Bytes::copy_from_slice(b"value_3")) | ||
.await?; | ||
|
||
println!("New Transaction"); | ||
let tx = kip_storage.new_transaction().await; | ||
|
||
println!( | ||
"RangeScan without key_3 By Transaction: {:?}", | ||
tx.range_scan(Bound::Unbounded, Bound::Excluded(b"key_3"))? | ||
); | ||
|
||
Ok(()) | ||
} |