Crates.io | informix_rust |
lib.rs | informix_rust |
version | 0.0.4 |
source | src |
created_at | 2024-09-13 04:39:11.349731 |
updated_at | 2024-09-13 13:02:36.371506 |
description | 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. |
homepage | |
repository | https://github.com/berrytern/informix-rust |
max_upload_size | |
id | 1373355 |
size | 45,827 |
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.
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
// 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(())
}