informix_rust

Crates.ioinformix_rust
lib.rsinformix_rust
version0.0.4
sourcesrc
created_at2024-09-13 04:39:11.349731
updated_at2024-09-13 13:02:36.371506
descriptionInformixRust 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.
homepage
repositoryhttps://github.com/berrytern/informix-rust
max_upload_size
id1373355
size45,827
João Pedro Miranda C. Hluchan (berrytern)

documentation

README

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(())
}
Commit count: 0

cargo fmt