arrow_odbc/
lib.rs

1//! Fill Apache Arrow arrays from ODBC data sources.
2//!
3//! ## Usage
4//!
5//! ```no_run
6//! use arrow_odbc::{odbc_api::{Environment, ConnectionOptions}, OdbcReaderBuilder};
7//!
8//! const CONNECTION_STRING: &str = "\
9//!     Driver={ODBC Driver 18 for SQL Server};\
10//!     Server=localhost;\
11//!     UID=SA;\
12//!     PWD=My@Test@Password1;\
13//! ";
14//!
15//! fn main() -> Result<(), anyhow::Error> {
16//!     // Your application is fine if you spin up only one Environment.
17//!     let odbc_environment = Environment::new()?;
18//!     
19//!     // Connect with database.
20//!     let connection = odbc_environment.connect_with_connection_string(
21//!         CONNECTION_STRING,
22//!         ConnectionOptions::default()
23//!     )?;
24//!
25//!     // This SQL statement does not require any arguments.
26//!     let parameters = ();
27//!
28//!     // Do not apply any timeout.
29//!     let timeout_sec = None;
30//!
31//!     // Execute query and create result set
32//!     let cursor = connection
33//!         .execute("SELECT * FROM MyTable", parameters, timeout_sec)?
34//!         .expect("SELECT statement must produce a cursor");
35//!
36//!     // Read result set as arrow batches. Infer Arrow types automatically using the meta
37//!     // information of `cursor`.
38//!     let arrow_record_batches = OdbcReaderBuilder::new().build(cursor)?;
39//!
40//!     for batch in arrow_record_batches {
41//!         // ... process batch ...
42//!     }
43//!
44//!     Ok(())
45//! }
46//! ```
47mod date_time;
48mod decimal;
49mod error;
50mod odbc_writer;
51mod reader;
52mod schema;
53
54// Rexport odbc_api and arrow to make it easier for downstream crates to depend to avoid version
55// mismatches
56pub use arrow;
57pub use odbc_api;
58
59pub use self::{
60    error::Error,
61    odbc_writer::{OdbcWriter, WriterError, insert_into_table, insert_statement_from_schema},
62    reader::{
63        BufferAllocationOptions, ColumnFailure, ConcurrentOdbcReader, OdbcReader,
64        OdbcReaderBuilder, TextEncoding,
65    },
66    schema::arrow_schema_from,
67};