Files
Baradb/clients/rust
dimgigov 359f945170
CI / test (push) Has been cancelled
CI / verify (push) Has been cancelled
Clients CI / build-server (push) Has been cancelled
Clients CI / test-python (push) Has been cancelled
Clients CI / test-javascript (push) Has been cancelled
Clients CI / test-nim (push) Has been cancelled
Clients CI / test-rust (push) Has been cancelled
fix(clients): repair Python & Rust tests, add container test orchestration
- Python: fix wire protocol test method names (bool_val -> bool, etc.)
- Python: make integration tests and example fully async with pytest-asyncio
- Rust: add tokio dev-dependency and convert integration tests to async/await
- Rust: update ping_test example to async
- Nim: remove committed ELF build artifact
- Docker: add BARADB_HOST/BARADB_PORT env vars to test containers
- Docker: fix docker-compose.test.yml usage (remove --abort-on-container-exit)
- Add scripts/test-clients.sh for sequential client test runs
- Remove docker-compose.test.yml from .gitignore so it is tracked
- Fix repository URLs in Python and Rust READMEs
2026-05-14 23:35:45 +03:00
..

BaraDB Async Rust Client

Official async Rust client for BaraDB — a multimodal database engine written in Nim.

Features

  • Async/await — fully non-blocking with Tokio runtime
  • Binary wire protocol — fast TCP communication
  • Query builder — fluent SQL construction
  • Parameterized queries — safe from SQL injection
  • Vector & JSON support — first-class multimodal types

Installation

Add to your Cargo.toml:

[dependencies]
baradb = "1.1"
tokio = { version = "1.35", features = ["full"] }

Or from source:

git clone https://github.com/barabadb/baradadb.git
cd clients/rust
cargo build

Quick Start

use baradb::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    let mut client = Client::connect("localhost", 9472).await?;
    let result = client.query("SELECT name, age FROM users WHERE age > 18").await?;
    for row in result.rows() {
        println!("{:?}", row);
    }
    client.close().await;
    Ok(())
}

Parameterized Queries

use baradb::{Client, WireValue};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    let mut client = Client::connect("localhost", 9472).await?;
    let result = client.query_params(
        "SELECT * FROM users WHERE age > $1 AND country = $2",
        &[WireValue::Int64(18), WireValue::String("BG".to_string())],
    ).await?;
    for row in result.rows() {
        println!("{:?}", row);
    }
    client.close().await;
    Ok(())
}

Query Builder

use baradb::{Client, QueryBuilder};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    let mut client = Client::connect("localhost", 9472).await?;
    let result = QueryBuilder::new(&mut client)
        .select(&["name", "email"])
        .from("users")
        .where_clause("active = true")
        .order_by("name", "ASC")
        .limit(10)
        .exec()
        .await?;
    for row in result.rows() {
        println!("{:?}", row);
    }
    client.close().await;
    Ok(())
}
use baradb::{Client, WireValue};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    let mut client = Client::connect("localhost", 9472).await?;
    let result = client.query_params(
        "SELECT id, name FROM products ORDER BY embedding <-> $1 LIMIT 5",
        &[WireValue::Vector(vec![0.1, 0.2, 0.3])],
    ).await?;
    client.close().await;
    Ok(())
}

Running Tests

Unit tests (no server):

cargo test --lib

Integration tests (requires server on localhost:9472):

# Start server
docker run -d -p 9472:9472 barabadb:latest

# Run all tests
cargo test

API Reference

Client::connect(host, port) -> Result<Client>

Creates a new async client connected to the given host and port.

Methods (all async)

  • await client.query(sql) -> Result<QueryResult> — execute SELECT-like query
  • await client.query_params(sql, params) -> Result<QueryResult> — parameterized query
  • await client.execute(sql) -> Result<usize> — execute DDL/DML, returns affected rows
  • await client.auth(token) -> Result<()> — JWT authentication
  • await client.ping() -> Result<bool> — health check
  • await client.close() — close connection

License

Apache-2.0