#database-driver #hana #driver #relational #serde

hdbconnect_async

An asynchronous pure rust database driver for SAP HANA(TM)

10 unstable releases (3 breaking)

0.28.5 Feb 9, 2024
0.28.4 Feb 5, 2024
0.28.3 Jan 19, 2024
0.27.0 Dec 31, 2023
0.25.1 Feb 2, 2023

#2254 in Database interfaces

Download history 1/week @ 2023-12-26 5/week @ 2024-01-02 10/week @ 2024-01-09 6/week @ 2024-01-16 5/week @ 2024-01-30 7/week @ 2024-02-06 10/week @ 2024-02-20 27/week @ 2024-02-27 1/week @ 2024-03-05 3/week @ 2024-03-12 11/week @ 2024-03-26 54/week @ 2024-04-02

69 downloads per month

MIT/Apache

785KB
16K SLoC

hdbconnect_async

Latest version Documentation License

An asynchronous pure rust SQL driver for SAP HANA(TM).

Usage

Add hdbconnect_async to the dependencies section in your project's Cargo.toml:

[dependencies]
hdbconnect_async = "0.28"

Assuming you have

  • a HANA accessible at port 39013 on host hxehost,
  • and you can log on to it as user HORST with password SeCrEt,

then a first simple test which sets up some table, inserts data and reads them back might look like this:

use hdbconnect_async::{Connection, HdbResult};

#[tokio::main]
pub async fn main() -> HdbResult<()> {
    let mut connection = Connection::new("hdbsql://HORST:SeCrEt@hxehost:39013").await?;

    // Cleanup if necessary, and set up a test table
    connection.multiple_statements_ignore_err(vec![
        "drop table FOO_SQUARE"
    ]).await;
    connection.multiple_statements(vec![
        "create table FOO_SQUARE ( f1 INT primary key, f2 BIGINT)",
    ]).await?;

    // Insert some test data
    let mut insert_stmt = connection.prepare(
        "insert into FOO_SQUARE (f1, f2) values(?,?)"
    ).await?;

    for i in 0..100 {
        insert_stmt.add_batch(&(i, i * i))?;
    }
    insert_stmt.execute_batch().await?;

    // Read the table data directly into a rust data structure
    let stmt = "select * from FOO_SQUARE order by f1 asc";
    let n_square: Vec<(i32, u64)> =
        connection.query(stmt).await?.try_into().await?;

    // Verify ...
    for (idx, (n, square)) in n_square.into_iter().enumerate() {
        assert_eq!(idx as i32, n);
        assert_eq!((idx * idx) as u64, square);
    }
    Ok(())
}

Documentation

See https://docs.rs/hdbconnect_async/ for the full functionality of hdbconnect_async.

There you find also more code examples, especially in the description of module code_examples.

TLS

See HANA in SCP for instructions how to obtain the necessary server certificate from a HANA in SAP Cloud Platform.

Features

rocket_pool

Adds an implementation of a rocket_db_pools database pool.

dist_tx

Adds support for distributed transactions, based on dist_tx.

Versions

See the change log.

Dependencies

~15–51MB
~1M SLoC