1 unstable release
0.0.4 | Sep 13, 2024 |
---|---|
0.0.3 |
|
0.0.2 |
|
0.0.1 |
|
#1184 in Database interfaces
30 downloads per month
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
- Download by site IBM-CSDK-Client or by link IBM-CSDK-Download
-
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