📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

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

TiDB Cloud LakeRustNotes
BOOLEANbool
TINYINTi8, u8
SMALLINTi16, u16
INTi32, u32
BIGINTi64, u64
FLOATf32
DOUBLEf64
DECIMALStringPrecision preserved
VARCHARStringUTF-8 encoded
BINARYVec<u8>

Date/Time Types

TiDB Cloud LakeRustNotes
DATEchrono::NaiveDateRequires chrono crate
TIMESTAMPchrono::NaiveDateTimeRequires chrono crate

Complex Types

TiDB Cloud LakeRustNotes
ARRAY[T]Vec<T>Nested arrays supported
TUPLE[T, U](T, U)Multiple element tuples
MAP[K, V]HashMap<K, V>Key-value mappings
VARIANTStringJSON-encoded
BITMAPStringBase64-encoded
GEOMETRYStringWKT format

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

Was this page helpful?