#relational #database #driver #serde #hana

hdbconnect

A synchronous pure rust database driver for SAP HANA(TM)

71 releases

0.26.0 Feb 16, 2023
0.24.0 Oct 20, 2022
0.23.0 Dec 29, 2020
0.22.2 Nov 22, 2020
0.0.26 Dec 7, 2016

#169 in Database interfaces

Download history 6/week @ 2022-12-03 7/week @ 2022-12-10 81/week @ 2022-12-17 28/week @ 2022-12-24 50/week @ 2022-12-31 15/week @ 2023-01-07 13/week @ 2023-01-14 20/week @ 2023-01-21 57/week @ 2023-01-28 21/week @ 2023-02-04 190/week @ 2023-02-11 155/week @ 2023-02-18 3/week @ 2023-02-25 8/week @ 2023-03-04 8/week @ 2023-03-11 153/week @ 2023-03-18

177 downloads per month

MIT/Apache

780KB
16K SLoC

hdbconnect

Latest version Documentation License

A synchronous pure rust SQL driver for SAP HANA(TM).

Check out hdbconnect_async if you need an asynchronous driver for SAP HANA.

Usage

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

[dependencies]
hdbconnect = "0.26"

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::{Connection, HdbResult};

pub fn main() -> HdbResult<()> {
    let mut connection = Connection::new("hdbsql://HORST:SeCrEt@hxehost:39013")?;

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

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

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

    // 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)?.try_into()?;

    // 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

The docs contain 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

r2d2_pool

Adds an implementation of a r2d2 database pool.

dist_tx

Adds support for distributed transactions, based on dist_tx.

Versions

See the change log.

Dependencies

~12–20MB
~443K SLoC