c55d3080cf
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
Documentation updates: - Fix v0.1.0 → v1.1.0 version numbers in en, ru, fa, zh docs - Add missing Window Functions, Multi-Tenant ERP, Supported Keywords sections to ru, fa, zh baraql.md (~105 lines each) - Expand Turkish and Arabic baraql.md (110 → 268 lines) - Expand Turkish and Arabic installation.md (62 → 307 lines) - Add new Bulgarian documentation files (18 new files) Client updates: - Python: Full async/await rewrite with asyncio, request queueing - Rust: Full async/await rewrite with tokio, async examples - Nim: Update README to v1.1.0 - All clients now support async patterns consistently
3.3 KiB
3.3 KiB
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/katehonz/barabaDB.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(())
}
Vector Search
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 queryawait client.query_params(sql, params) -> Result<QueryResult>— parameterized queryawait client.execute(sql) -> Result<usize>— execute DDL/DML, returns affected rowsawait client.auth(token) -> Result<()>— JWT authenticationawait client.ping() -> Result<bool>— health checkawait client.close()— close connection
License
Apache-2.0