Skip to content

TriCoreDB for Rust

0.1.0

The official Rust client: SQL, documents, cache, vectors and graphs over one native connection.

Install

cargo
cargo add tricoredb
Cargo.toml
[dependencies]
tricoredb = "0.1"

Requirements

  • Rust 1.85 or later
  • A TriCoreDB server, 0.1.0-rc.1 or later (install one)

Highlights

  • Blocking API, no async runtime required
  • Typed errors you branch on by kind and code
  • TLS through rustls, optional
  • Transactions, connection pool, TLS and mutual TLS

Quick start

src/main.rs
use tricoredb::{params, Client, Options};

fn main() -> tricoredb::Result<()> {
    let mut db = Client::connect(&Options::new("127.0.0.1", 8427).user("admin").secret("your-password"))?;

    db.execute("CREATE TABLE IF NOT EXISTS users (id INT PRIMARY KEY, name TEXT)")?;
    db.execute_params("INSERT INTO users VALUES (?, ?)", &params![1, "O'Hara"])?;

    let rows = db.query_params("SELECT name FROM users WHERE id = ?", &params![1])?;
    println!("{:?}", rows.get(0, "name")); // Some("O'Hara")

    db.cache_set("sessions", "u1", b"token")?;
    if let Some(token) = db.cache_get("sessions", "u1")? {
        println!("{} bytes", token.len());
    }
    Ok(())
}

TLS

This example connects without TLS, which matches the development container. The default image requires TLS. The README shows how to connect with a CA certificate, and documents every call.