A Rust SDK for interacting with HelixDB - providing a simple, type-safe interface for database operations.
- Type-safe query interface using Serde serialization/deserialization
- Async/await support
- Configurable port settings
- Custom client implementation support via
HelixDBClient
trait
Add this to your Cargo.toml
:
[dependencies]
helix-rs = "0.1.0"
use helix_rs::HelixDB;
use serde::{Serialize, Deserialize};
// Define your data structures
#[derive(Serialize)]
struct UserInput {
name: String,
age: i32,
}
#[derive(Deserialize)]
struct UserOutput {
id: String,
name: String,
age: i32,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Initialize the client
let client = HelixDB::new(None); // Uses default port 6969
// Create a user
let input = UserInput {
name: "John".to_string(),
age: 20,
};
let result: UserOutput = client.query("addUser", &input).await?;
println!("Created user with ID: {}", result.id);
Ok(())
}
You can specify a custom port when initializing the client:
let client = HelixDB::new(Some(8080)); // Uses port 8080
You can implement your own client by implementing the HelixDBClient
trait:
use helix_rs::HelixDBClient;
struct MyCustomClient {
// Your implementation details
}
impl HelixDBClient for MyCustomClient {
fn new(port: Option<u16>) -> Self {
// Your initialization logic
}
async fn query<T, R>(&self, endpoint: &str, data: &T) -> anyhow::Result<R>
where
T: Serialize,
R: for<'de> Deserialize<'de>
{
// Your query implementation
}
}
- Rust 1.56 or higher
- Running HelixDB instance
- Tokio runtime for async operations