7 releases (4 breaking)

new 0.7.1 Nov 20, 2025
0.7.0 Nov 20, 2025
0.6.0 Oct 17, 2025
0.5.1 Jun 24, 2025
0.3.0 Dec 8, 2024

#1701 in Procedural macros

Download history 877/week @ 2025-07-30 1205/week @ 2025-08-06 1423/week @ 2025-08-13 1653/week @ 2025-08-20 1133/week @ 2025-08-27 1235/week @ 2025-09-03 1170/week @ 2025-09-10 180/week @ 2025-09-17 138/week @ 2025-09-24 124/week @ 2025-10-01 306/week @ 2025-10-08 411/week @ 2025-10-15 376/week @ 2025-10-22 385/week @ 2025-10-29 245/week @ 2025-11-05 609/week @ 2025-11-12

1,691 downloads per month
Used in trino-rust-client

MIT license

9KB
141 lines

Trino rust client

A trino client library written in rust.

This project have been forked on 08/12/24 from the great : prusto made by @nooberfsh.

Fork rationale :

  • Remove presto support
  • Add advanced trino features.
  • Rename things as "trino"

Features

authn:

  • Basic Auth
  • Jwt Auth

protocols:

  • Spooling Protocol (for efficient large result set handling)

Installation

# Cargo.toml
[dependencies]
trino-rust-client = "0.9.1"

# For spooling protocol support
trino-rust-client = { version = "0.9.1", features = ["spooling"] }

Example

Basic example

use trino_rust_client::{ClientBuilder, Trino};

#[derive(Trino, Debug)]
struct Foo {
    a: i64,
    b: f64,
    c: String,
}

#[tokio::main]
async fn main() {
    let cli = ClientBuilder::new("user", "localhost")
        .port(8090)
        .catalog("catalog")
        .build()
        .unwrap();

    let sql = "select 1 as a, cast(1.1 as double) as b, 'bar' as c ";

    let data = cli.get_all::<Foo>(sql.into()).await.unwrap().into_vec();

    for r in data {
        println!("{:?}", r)
    }
}

Https & Jwt example

use trino_rust_client::{ClientBuilder, Trino};

#[derive(Trino, Debug)]
struct Foo {
    a: i64,
    b: f64,
    c: String,
}

#[tokio::main]
async fn main() {
    let auth = Auth::Jwt("your access token");

    let cli = ClientBuilder::new("user", "localhost")
        .port(8443)
        .secure(true)
        .auth(auth)
        .catalog("catalog")
        .build()
        .unwrap();

    let sql = "select 1 as a, cast(1.1 as double) as b, 'bar' as c ";

    let data = cli.get_all::<Foo>(sql.into()).await.unwrap().into_vec();

    for r in data {
        println!("{:?}", r)
    }
}

Example dealing with fields not known at compile time

use trino_rust_client::{ClientBuilder, Row, Trino};

#[tokio::main]
async fn main() {
    let cli = ClientBuilder::new("user", "localhost")
        .port(8080)
        .catalog("catalog")
        .build()
        .unwrap();

    let sql = "select first_name, last_name from users";

    let rows = cli.get_all::<Row>(sql.into()).await.unwrap().into_vec();

    for row in rows {
        let first_name = row.value().get(0).unwrap();
        let last_name = row.value().get(1).unwrap();
        println!("{} : {}", first_name, last_name);
    }
}

Spooling Protocol example

use trino_rust_client::{ClientBuilder, Trino};

#[derive(Trino, Debug)]
struct User {
    id: i64,
    name: String,
    email: String,
}

#[tokio::main]
async fn main() {
    let cli = ClientBuilder::new("user", "localhost")
        .port(8080)
        .catalog("memory")
        .schema("default")
        .spooling_encoding("json+zstd")  // Enable spooling with compression
        .max_concurrent_segments(10)      // Optional: control concurrent downloads
        .build()
        .unwrap();

    let sql = "SELECT id, name, email FROM users LIMIT 1000";

    let data = cli.get_all::<User>(sql.into()).await.unwrap();

    println!("Retrieved {} rows", data.len());

    for user in data.as_slice() {
        println!("{:?}", user);
    }
}

License

MIT

Dependencies

~165–580KB
~14K SLoC