13 releases
new 0.1.12 | Nov 16, 2024 |
---|---|
0.1.11 | Sep 23, 2024 |
0.1.9 | Aug 25, 2024 |
0.1.6 | Jul 13, 2024 |
#1795 in Database interfaces
106 downloads per month
34KB
579 lines
rt-pods-client
Rust Client for RT(Radix Tree)-Pods. RT-Pods is a RadixTree DBMS written in Rust.
Description
Rust client to interface with a running RT-Pods deployment.
For documentation beyond the doc comments on the methods and docs.rs; or how to get started with RT-Pods, see the rt-pods
repository.
Installation
cargo add rt-pods-client
Example Usage
use rt_pods_client::{
results::SearchResult, BatchOperation, RtPods, SearchOptionsBuilder, SearchSort,
SearchSortOrder,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let rt_pods = RtPods::new(vec!["127.0.0.1:1337"], None)?;
rt_pods.create_radix_tree("1337").await?;
rt_pods
.batch_operation(
"1337",
vec![
BatchOperation::Insert(("/root".to_string(), None)),
BatchOperation::Insert(("/root/images".to_string(), None)),
BatchOperation::Insert(("/root/images/owls".to_string(), None)),
BatchOperation::Insert(("/root/images/owls/snow.jpg".to_string(), Some("data".to_string()))),
BatchOperation::Insert(("/root/images/owls/grey.jpg".to_string(), None)),
],
)
.await?;
let search_result = rt_pods
.search(
"1337",
"/root/",
SearchOptionsBuilder::new(12)
.sort(vec![SearchSort::Length(SearchSortOrder::Ascending)])
.limit(12)
.predictive(true)
.build(),
)
.await?;
if let SearchResult::Ok(results) = search_result {
println!("{:?}", results);
// Logs
// [
// ("images", None),
// ("images/owls", None),
// ("images/owls/snow.jpg", Some("data")),
// ("images/owls/grey.jpg", None),
// ]
}
rt_pods.remove("1337", "/root/images/owls/grey.jpg").await?;
rt_pods.delete_radix_tree("1337").await?;
Ok(())
}
// Cluster
let rt_pods = RtPods::new(vec![
"127.0.0.1:1337",
"127.0.0.1:1338",
"127.0.0.1:1339",
], None)?;
// It is highly recommended to at-least sync on startup
rt_pods.sync().await;
// Syncing with the cluster can let the client know
// about newly registered radix trees since the initial
// sync on construction and improve routing performance.
let rt_pods_clone = rt_pods.clone();
tokio::spawn(async move {
loop {
rt_pods_clone.sync().await;
sleep(Duration::from_secs(60)).await;
}
});
Contributing
Open to any contributions, but this repository must mirror the rt-pods-client-ts
Typescript client completely; meaning any proposed changes here will need to be carried over to the next release of rt-pods-client-ts
or any following clients for other languages.
License
MIT License
Copyright (c) 2024 Robert Lopez
See LICENSE.md
Project status
I plan to continue maintaining this project as long as I maintain rt-pods
.
Dependencies
~6–18MB
~225K SLoC