Connect to TiDB Cloud Lake Using Rust
The official Rust driver provides native connectivity with async/await support and comprehensive type safety for Rust applications.
Installation
Add the driver to your Cargo.toml:
[dependencies]
lake-driver = "0.1.5-alpha.2"
tokio = { version = "1", features = ["full"] }
Connection String: See drivers overview for DSN format and examples.
Key Features
- ✅ Async/Await Support: Built for modern Rust async programming
- ✅ Type Safety: Strong type mapping with Rust's type system
- ✅ Connection Pooling: Efficient connection management
- ✅ Stage Operations: Upload/download data to/from TiDB Cloud Lake stages
- ✅ Streaming Results: Process large result sets efficiently
Data Type Mappings
Basic Types
Date/Time Types
Complex Types
Basic Usage
Here's a simple example demonstrating DDL, write, and query operations:
use lake_driver::Client;
use tokio_stream::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to TiDB Cloud Lake
let client = Client::new("<your-dsn>".to_string());
let conn = client.get_conn().await?;
// DDL: Create table
conn.exec("CREATE TABLE IF NOT EXISTS users (id INT, name VARCHAR, created_at TIMESTAMP)")
.await?;
// Write: Insert data
conn.exec("INSERT INTO users VALUES (1, 'Alice', '2023-12-01 10:00:00')")
.await?;
conn.exec("INSERT INTO users VALUES (2, 'Bob', '2023-12-01 11:00:00')")
.await?;
// Query: Select data
let mut rows = conn.query_iter("SELECT id, name, created_at FROM users ORDER BY id")
.await?;
while let Some(row) = rows.next().await {
let (id, name, created_at): (i32, String, chrono::NaiveDateTime) =
row?.try_into()?;
println!("User {}: {} (created: {})", id, name, created_at);
}
Ok(())
}
Resources
- Crates.io: lake-driver
- GitHub Repository: LakeSQL/driver
- Rust Documentation: docs.rs/lake-driver