#sql-database #database-interface #sql #csdk #informix #client-sdk

sys informix_rust

InformixRust is a Rust library that provides a safe and efficient way to interact with Informix databases. It wraps the Informix CSDK (Client SDK) to offer a more Rust-friendly interface for database operations.

1 unstable release

0.0.4 Sep 13, 2024
0.0.3 Sep 13, 2024
0.0.2 Sep 13, 2024
0.0.1 Sep 13, 2024

#1047 in Database interfaces

Download history 241/week @ 2024-09-08 76/week @ 2024-09-15 11/week @ 2024-09-22 18/week @ 2024-09-29 3/week @ 2024-10-06

149 downloads per month

Apache-2.0

25KB
464 lines

InformixRust

InformixRust is a Rust library that provides a safe and efficient way to interact with Informix databases. It wraps the Informix CSDK (Client SDK) to offer a more Rust-friendly interface for database operations.

Features

  • Safe Rust wrapper around Informix CSDK
  • Connection management with auto-reconnection support(todo)
  • Prepared statements with parameter binding
  • Efficient result set fetching
  • Support for various SQL data types including dates

Installation

  • Informix

  • Add this to your Cargo.toml:

    [dependencies]
    informix_rust = "0.0.4"
    chrono = "0.4"
    
  • Set enviroment variables

    export INFORMIXDIR=/opt/IBM/informix
    export CSDK_HOME=$INFORMIXDIR
    export LD_LIBRARY_PATH=$INFORMIXDIR/lib:$INFORMIXDIR/lib/esql:$INFORMIXDIR/lib/cli
    export INFORMIXSQLHOSTS=$INFORMIXDIR/etc/sqlhosts
    

Usage

// File: examples/simple_query.rs
use informix_rust::{Connection, errors::Result};
use chrono::NaiveDate;
use std::env;

fn main() -> Result<()> {
    println!("Starting the application");

    let conn = Connection::new()?;
    println!("Connection object created");

    let conn_string = &env::var("INFORMIXDB_CONN_PARAMS").expect("INFORMIXDB_CONN_PARAMS must be set");
    conn.connect_with_string(conn_string)?;

    let query = "SELECT * FROM your_table WHERE id = ? AND date <= ?";
    let stmt = conn.prepare(query)?;

    let id = 1;
    let date = NaiveDate::from_ymd_opt(2024, 9, 7).unwrap();

    stmt.bind_parameter(1, &id)?;
    stmt.bind_parameter(2, &date)?;

    stmt.execute()?;

    while let Some(row) = stmt.fetch()? {
        println!("{:?}", row);
    }

    Ok(())
}

Dependencies

~1–1.4MB
~23K SLoC