Update documentation and clients for v1.1.0
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
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
This commit is contained in:
@@ -3,34 +3,65 @@
|
||||
|
||||
use baradb::{Client, QueryBuilder, WireValue};
|
||||
|
||||
fn example_connection() -> Result<(), Box<dyn std::error::Error>> {
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
println!("BaraDB Rust Client Examples");
|
||||
println!("Make sure BaraDB is running on localhost:9472");
|
||||
println!();
|
||||
|
||||
if let Err(e) = example_connection().await {
|
||||
eprintln!("ERROR: {}", e);
|
||||
}
|
||||
|
||||
if let Err(e) = example_simple_query().await {
|
||||
eprintln!("ERROR: {}", e);
|
||||
}
|
||||
|
||||
if let Err(e) = example_parameterized_query().await {
|
||||
eprintln!("ERROR: {}", e);
|
||||
}
|
||||
|
||||
if let Err(e) = example_query_builder().await {
|
||||
eprintln!("ERROR: {}", e);
|
||||
}
|
||||
|
||||
if let Err(e) = example_vector().await {
|
||||
eprintln!("ERROR: {}", e);
|
||||
}
|
||||
|
||||
if let Err(e) = example_ddl_dml().await {
|
||||
eprintln!("ERROR: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
async fn example_connection() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
println!("=== Connection ===");
|
||||
let mut client = Client::connect("127.0.0.1", 9472)?;
|
||||
let mut client = Client::connect("127.0.0.1", 9472).await?;
|
||||
println!("Connected: {}", client.is_connected());
|
||||
println!("Ping: {}", client.ping()?);
|
||||
client.close();
|
||||
println!("Ping: {}", client.ping().await?);
|
||||
client.close().await;
|
||||
println!("Connected after close: {}", client.is_connected());
|
||||
println!();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn example_simple_query() -> Result<(), Box<dyn std::error::Error>> {
|
||||
async fn example_simple_query() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
println!("=== Simple Query ===");
|
||||
let mut client = Client::connect("127.0.0.1", 9472)?;
|
||||
let result = client.query("SELECT 42 as answer, 'BaraDB' as db")?;
|
||||
let mut client = Client::connect("127.0.0.1", 9472).await?;
|
||||
let result = client.query("SELECT 42 as answer, 'BaraDB' as db").await?;
|
||||
println!("Columns: {:?}", result.columns());
|
||||
println!("Row count: {}", result.row_count());
|
||||
for row in result.rows() {
|
||||
println!(" {:?}", row);
|
||||
}
|
||||
client.close();
|
||||
client.close().await;
|
||||
println!();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn example_parameterized_query() -> Result<(), Box<dyn std::error::Error>> {
|
||||
async fn example_parameterized_query() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
println!("=== Parameterized Query ===");
|
||||
let mut client = Client::connect("127.0.0.1", 9472)?;
|
||||
let mut client = Client::connect("127.0.0.1", 9472).await?;
|
||||
let result = client.query_params(
|
||||
"SELECT $1 as num, $2 as txt, $3 as flag",
|
||||
&[
|
||||
@@ -38,18 +69,18 @@ fn example_parameterized_query() -> Result<(), Box<dyn std::error::Error>> {
|
||||
WireValue::String("hello world".to_string()),
|
||||
WireValue::Bool(true),
|
||||
],
|
||||
)?;
|
||||
).await?;
|
||||
for row in result.rows() {
|
||||
println!(" {:?}", row);
|
||||
}
|
||||
client.close();
|
||||
client.close().await;
|
||||
println!();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn example_query_builder() -> Result<(), Box<dyn std::error::Error>> {
|
||||
async fn example_query_builder() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
println!("=== Query Builder ===");
|
||||
let mut client = Client::connect("127.0.0.1", 9472)?;
|
||||
let mut client = Client::connect("127.0.0.1", 9472).await?;
|
||||
let sql = QueryBuilder::new(&mut client)
|
||||
.select(&["id", "name"])
|
||||
.from("users")
|
||||
@@ -58,70 +89,49 @@ fn example_query_builder() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.limit(5)
|
||||
.build();
|
||||
println!("Generated SQL: {}", sql);
|
||||
client.close();
|
||||
client.close().await;
|
||||
println!();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn example_vector() -> Result<(), Box<dyn std::error::Error>> {
|
||||
async fn example_vector() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
println!("=== Vector Value ===");
|
||||
let mut client = Client::connect("127.0.0.1", 9472)?;
|
||||
let mut client = Client::connect("127.0.0.1", 9472).await?;
|
||||
let result = client.query_params(
|
||||
"SELECT $1 as embedding",
|
||||
&[WireValue::Vector(vec![0.1, 0.2, 0.3, 0.4])],
|
||||
)?;
|
||||
).await?;
|
||||
for row in result.rows() {
|
||||
println!(" {:?}", row);
|
||||
}
|
||||
client.close();
|
||||
client.close().await;
|
||||
println!();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn example_ddl_dml() -> Result<(), Box<dyn std::error::Error>> {
|
||||
async fn example_ddl_dml() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
println!("=== DDL & DML ===");
|
||||
let mut client = Client::connect("127.0.0.1", 9472)?;
|
||||
let mut client = Client::connect("127.0.0.1", 9472).await?;
|
||||
|
||||
let _ = client.execute("DROP TABLE IF EXISTS demo_products");
|
||||
let _ = client.execute("DROP TABLE IF EXISTS demo_products").await;
|
||||
|
||||
client.execute(
|
||||
"CREATE TABLE demo_products (id INT PRIMARY KEY, name STRING, price FLOAT)",
|
||||
)?;
|
||||
).await?;
|
||||
let affected = client.execute(
|
||||
"INSERT INTO demo_products (id, name, price) VALUES (1, 'Widget', 9.99)",
|
||||
)?;
|
||||
).await?;
|
||||
println!("Insert affected rows: {}", affected);
|
||||
|
||||
let result = client.query("SELECT * FROM demo_products")?;
|
||||
let result = client.query("SELECT * FROM demo_products").await?;
|
||||
println!("Select returned {} row(s)", result.row_count());
|
||||
for row in result.rows() {
|
||||
println!(" {:?}", row);
|
||||
}
|
||||
|
||||
client.execute("DROP TABLE demo_products")?;
|
||||
client.execute("DROP TABLE demo_products").await?;
|
||||
println!("Table dropped");
|
||||
client.close();
|
||||
client.close().await;
|
||||
println!();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("BaraDB Rust Client Examples");
|
||||
println!("Make sure BaraDB is running on localhost:9472");
|
||||
println!();
|
||||
|
||||
let examples: Vec<fn() -> Result<(), Box<dyn std::error::Error>>> = vec![
|
||||
example_connection,
|
||||
example_simple_query,
|
||||
example_parameterized_query,
|
||||
example_query_builder,
|
||||
example_vector,
|
||||
example_ddl_dml,
|
||||
];
|
||||
|
||||
for example in examples {
|
||||
if let Err(e) = example() {
|
||||
eprintln!("ERROR: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user