83 releases (17 breaking)

new 0.18.0 May 17, 2024
0.17.1 Apr 26, 2024
0.16.0 Mar 25, 2024
0.12.1 Dec 26, 2023
0.1.3 Mar 30, 2023

#65 in Database interfaces

Download history 2029/week @ 2024-01-27 1619/week @ 2024-02-03 62/week @ 2024-02-10 1688/week @ 2024-02-17 2802/week @ 2024-02-24 2341/week @ 2024-03-02 2001/week @ 2024-03-09 2721/week @ 2024-03-16 2621/week @ 2024-03-23 1845/week @ 2024-03-30 2087/week @ 2024-04-06 1487/week @ 2024-04-13 1707/week @ 2024-04-20 1453/week @ 2024-04-27 2176/week @ 2024-05-04 2976/week @ 2024-05-11

8,562 downloads per month
Used in 3 crates

Apache-2.0

200KB
4.5K SLoC

Databend Driver

Databend unified SQL client for RestAPI and FlightSQL

crates.io License

usage

exec

use databend_driver::Client;

let dsn = "databend://root:@localhost:8000/default?sslmode=disable".to_string();
let client = Client::new(dsn);
let conn = client.get_conn().await.unwrap();

let sql_create = "CREATE TABLE books (
    title VARCHAR,
    author VARCHAR,
    date Date
);";
conn.exec(sql_create).await.unwrap();
let sql_insert = "INSERT INTO books VALUES ('The Little Prince', 'Antoine de Saint-Exupéry', '1943-04-06');";
conn.exec(sql_insert).await.unwrap();

query row

let row = conn.query_row("SELECT * FROM books;").await.unwrap();
let (title,author,date): (String,String,i32) = row.unwrap().try_into().unwrap();
println!("{} {} {}", title, author, date);

query iter

let mut rows = conn.query_iter("SELECT * FROM books;").await.unwrap();
while let Some(row) = rows.next().await {
    let (title,author,date): (String,String,chrono::NaiveDate) = row.unwrap().try_into().unwrap();
    println!("{} {} {}", title, author, date);
}

Type Mapping

Databend Types

General Data Types

Databend Rust
BOOLEAN bool
TINYINT i8,u8
SMALLINT i16,u16
INT i32,u32
BIGINT i64,u64
FLOAT f32
DOUBLE f64
DECIMAL String
DATE chrono::NaiveDate
TIMESTAMP chrono::NaiveDateTime
VARCHAR String
BINARY Vec<u8>

Semi-Structured Data Types

Databend Rust
ARRAY[T] Vec<T>
TUPLE[T, U] (T, U)
MAP[K, V] HashMap<K, V>
VARIANT String
BITMAP String
GEOMETRY String

Note: VARIANT is a json encoded string. Example:

CREATE TABLE example (
    data VARIANT
);
INSERT INTO example VALUES ('{"a": 1, "b": "hello"}');
let row = conn.query_row("SELECT * FROM example limit 1;").await.unwrap();
let (data,): (String,) = row.unwrap().try_into().unwrap();
let value: serde_json::Value = serde_json::from_str(&data).unwrap();
println!("{:?}", value);

Dependencies

~26–43MB
~660K SLoC