odbc-iter
is a Rust high level database access library based on odbc
crate that uses native ODBC drivers to access a variety of databases.
With this library you can:
* connect to any database supporting ODBC standard (e.g. via unixodbc
library and ODBC database driver),
* run one-off, prepared or parametrized queries,
* iterate result set via standard Iterator
interface,
* automatically convert rows into:
* tuples of Rust standard types,
* custom type implementing a trait,
* vector of dynamically typed values,
* create thread local connections for multithreaded applications.
Things still missing:
* support for DECIMAL
types - currently DECIMAL
columns need to be cast to DOUBLE
on the query (PR welcome),
* rest of this list - please open issue in GitHub
issue tracker for missing functionality, bugs, etc..
```rust use odbc_iter::{Odbc, ValueRow};
// Connect to database using connection string let connectionstring = std::env::var("DBCONNECTIONSTRING") .expect("DBCONNECTIONSTRING environment not set"); let mut connection = Odbc::connect(&connectionstring) .expect("failed to connect to database");
// Handle statically guards access to connection and provides query functionality let mut db = connection.handle();
// Get single row single column value
println!("{}", db.query::
// Iterate rows with single column
for row in db.query::
// Iterate rows with multiple columns for row in db.query::<(String, i8)>( "SELECT 'hello world', CAST(24 AS TINYINT) UNION SELECT 'foo bar', CAST(32 AS TINYINT)") .expect("failed to run query") { let (string, number) = row.expect("failed to fetch row"); println!("{} {}", string, number); } // Prints: // hello world 24 // foo bar 32
// Iterate rows with dynamically typed values using ValueRow
type that can represent
// any row
for row in db.query::