Quickstart

Here we’ll briefly tour basic features of ADBC with Rust using the SQLite driver.

Installation

Add a dependency on adbc_core and adbc_driver_manager:

cargo add adbc_core adbc_driver_manager

Note

If you get a compiler error (E0308, mismatched types) and a note about multiple versions of the arrow crates in the dependency graph when you run cargo build, you can downgrade crate versions so you only have one version of the arrow crates in your workspace:

cargo update -p arrow-array@57.0.0 -p arrow-schema@57.0.0 --precise 56.2.0

Note the exact versions in the command above may need to be changed. Use cargo tree to find the versions affecting your workspace. See the Version Incompatibility Hazards in the Cargo documentation for more information.

Installing Drivers

See Installing Drivers for instructions on installing ADBC drivers for the database you want to connect to. For the example below, you could install dbc and then install the SQLite driver with:

dbc install sqlite

Loading a Driver

Use ManagedDriver::load_from_name to locate and load a driver by name. The driver manager searches for a driver manifest (e.g. sqlite.toml) in the directories controlled by load_flags. See ADBC Driver Manager and Manifests for details on manifest search paths.

use adbc_core::options::AdbcVersion;
use adbc_core::{Connection, Database, Driver, Statement, LOAD_FLAG_DEFAULT};
use adbc_driver_manager::ManagedDriver;

let mut driver = ManagedDriver::load_from_name(
    "sqlite",
    None,
    AdbcVersion::default(),
    LOAD_FLAG_DEFAULT,
    None,
)
.expect("Failed to load driver");
let db = driver.new_database().expect("Failed to create database handle");
let mut conn = db.new_connection().expect("Failed to create connection");

Running Queries

To run queries, create a statement and set a query:

let mut stmt = conn.new_statement().expect("Failed to create statement");
stmt.set_sql_query("SELECT 1").expect("Failed to set SQL query");

Execute the query to get an Arrow RecordBatchReader:

let reader = stmt.execute().expect("Failed to execute statement");
for batch in reader {
    let batch = batch.expect("Failed to read batch");
    println!("{:?}", batch);
}

Next Steps