siodb_driver

Crates.iosiodb_driver
lib.rssiodb_driver
version0.6.5
sourcesrc
created_at2020-05-21 12:27:20.736566
updated_at2020-06-01 13:57:37.5583
descriptionDriver for Siodb database.
homepagehttps://siodb.io
repositoryhttps://github.com/siodb/siodb-rust-driver
max_upload_size
id244071
size176,616
Nicolas Penot (niolap)

documentation

README

Rust driver for Siodb

A simple driver for Siodb written in pure Rust.

Features

  • Support of URI
  • Connections to Siodb (TLS, TCP, Unix socket)
  • Authentication to Siodb
  • Query execution
  • DML execution

Installation

Add the crate dependency with the version you desire into Cargo.toml:

[dependencies]
siodb_driver = "*"

Quick setup

Start Siodb in a container and get the RSA key for root user locally:

docker run -p 127.0.0.1:50000:50000/tcp --name siodb siodb/siodb
docker exec -it siodb cat /home/siodb/.ssh/id_rsa > ~/root_id_rsa

Example

    let uri = "siodbs://root@localhost:50000?identity_file=/home/nico/root_id_rsa";

    let mut siodb_conn = SiodbConn::new(&uri).expect(&format!("Error connecting to URI '{}'", uri));

    if siodb_conn
        .query_row("select name from sys_databases where name = 'TEST_DB'".to_string())
        .is_none()
    {
        siodb_conn
            .execute("CREATE DATABASE test_db".to_string())
            .expect(&format!("Database creation error."));
    }

    if siodb_conn
        .query_row("select name from test_db.sys_tables where name = 'TEST_TABLE'".to_string())
        .is_none()
    {
        siodb_conn
            .execute(
                "CREATE TABLE test_db.test_table
                (
                   ctinyintmin  TINYINT,
                   ctinyintmax  TINYINT,
                   ctinyuint    TINYUINT,
                   csmallintmin SMALLINT,
                   csmallintmax SMALLINT,
                   csmalluint   SMALLUINT,
                   cintmin      INT,
                   cintmax      INT,
                   cuint        UINT,
                   cbigintmin   BIGINT,
                   cbigintmax   BIGINT,
                   cbiguint     BIGUINT,
                   cfloatmin    FLOAT,
                   cfloatmax    FLOAT,
                   cdoublemin   DOUBLE,
                   cdoublemax   DOUBLE,
                   ctext        TEXT,
                   cts          TIMESTAMP
                )"
                .to_string(),
            )
            .expect(&format!("Table creation error."));
    }

    siodb_conn
        .execute(
            "INSERT INTO test_db.test_table
             VALUES      ( -128,
                           127,
                           255,
                           -32768,
                           32767,
                           65535,
                           -2147483648,
                           2147483647,
                           4294967295,
                           -9223372036854775808,
                           9223372036854775807,
                           18446744073709551615,
                           222.222,
                           222.222,
                           222.222,
                           222.222,
                           '汉字',
                           CURRENT_TIMESTAMP ) "
                .to_string(),
        )
        .expect(&format!("Insertion error."));

    println!("Affected row(s): {}", siodb_conn.get_affected_row_count());

    siodb_conn
        .query("select * from test_db.test_table".to_string())
        .expect(&format!("Query error"));

    while siodb_conn.next().unwrap() {
        for data in siodb_conn.scan() {
            if data.is_none() {
                println!("Value: Null");
            } else {
                println!("Value: {}", data.as_ref().unwrap());
            }
        }
    }

    println!("Row(s): {}", siodb_conn.get_row_count());

    siodb_conn.close().unwrap();

URI

To identify a Siodb resource, the driver use the URI format.

For TLS connection (default):

siodbs://root@localhost:50000?identity_file=/home/siodb/.ssh/id_rsa

For TCP plain text connection:

siodb://root@unix_socket?identity_file=/home/siodb/.ssh/id_rsa

For Unix socket connection:

siodbu://root@unix_socket?identity_file=/home/siodb/.ssh/id_rsa

The above example will connect you to the localhost with port number 50000. The driver will do the authentication with the Siodb user root and the identity file /home/siodb/.ssh/id_rsa.

Options

  • identity_file: the path to the RSA private key.
  • unix_socket: indicate the path of the Unix socket used by Siodb to connect locally.
  • trace: to trace everything within the driver to sdtout.

Support Siodb

Do you like this project? Tell it by clicking the star 🟊 on the top right of this page ☝☝

Documentation

We write the Siodb documentation in Markdow and it is available in the folder docs/users/docs. If you prefer a more user friendly format, the same documentation is available online here.

Contribution

Please refer to the Contributing file.

Support

  • Report your issue with Siodb 👉 here.
  • Report your issue with the driver 👉 here.
  • Ask a question 👉 here.
  • Siodb Slack space 👉 here.

Follow Siodb

License

Licensed under Apache License version 2.0.

Commit count: 10

cargo fmt