Function arrow_odbc::arrow_schema_from

source ·
pub fn arrow_schema_from(
    resut_set_metadata: &mut impl ResultSetMetadata
) -> Result<Schema, Error>
Expand description

Query the metadata to create an arrow schema. This method is invoked automatically for you by [crate::OdbcReader::new]. You may want to call this method in situtation ther you want to create an arrow schema without creating the reader yet.

§Example

use anyhow::Error;

use arrow_odbc::{arrow_schema_from, arrow::datatypes::Schema, odbc_api::Connection};

fn fetch_schema_for_table(
    table_name: &str,
    connection: &Connection<'_>
) -> Result<Schema, Error> {
    // Query column with values to get a cursor
    let sql = format!("SELECT * FROM {}", table_name);
    let mut prepared = connection.prepare(&sql)?;
     
    // Now that we have prepared statement, we want to use it to query metadata.
    let schema = arrow_schema_from(&mut prepared)?;
    Ok(schema)
}