Files
Baradb/clients/rust
dimgigov a28c845476
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
Bump version to 1.1.4 across all components
2026-05-17 20:57:19 +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://codeberg.org/baraba/baradb
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