Expand description
Load and use ADBC drivers.
The driver manager provides an implementation of the ADBC interface which
uses FFI to wrap an object file implementation of
adbc.h.
There are two ways that drivers can be used:
- By linking (either statically or dynamically) the driver implementation at link-time and then using ManagedDriver::load_static.
- By loading the driver implementation at run-time (with
dlopen/LoadLibrary) using ManagedDriver::load_dynamic_from_name or ManagedDriver::load_dynamic_from_filename.
Drivers are initialized using a function provided by the driver as a main
entrypoint, canonically called AdbcDriverInit. Although many will use a
different name to support statically linking multiple drivers within the
same program.
§Using across threads
ManagedDriver, ManagedDatabase, ManagedConnection and ManagedStatement can be used across threads though all of their operations are serialized under the hood. They hold their inner implementations within std::sync::Arc, so they are cheaply clonable.
§Example
let opts = [(OptionDatabase::Uri, ":memory:".into())];
let mut driver = ManagedDriver::load_dynamic_from_name("adbc_driver_sqlite", None, AdbcVersion::V100)?;
let database = driver.new_database_with_opts(opts)?;
let mut connection = database.new_connection()?;
let mut statement = connection.new_statement()?;
// Define some data.
let columns: Vec<Arc<dyn Array>> = vec![
Arc::new(Int64Array::from(vec![1, 2, 3, 4])),
Arc::new(Float64Array::from(vec![1.0, 2.0, 3.0, 4.0])),
Arc::new(StringArray::from(vec!["a", "b", "c", "d"])),
];
let schema = Schema::new(vec![
Field::new("a", DataType::Int64, true),
Field::new("b", DataType::Float64, true),
Field::new("c", DataType::Utf8, true),
]);
let input: RecordBatch = RecordBatch::try_new(Arc::new(schema), columns)?;
// Ingest data.
statement.set_option(OptionStatement::TargetTable, "my_table".into())?;
statement.bind(input.clone())?;
statement.execute_update()?;
// Extract data.
statement.set_sql_query("select * from my_table")?;
let output = statement.execute()?;
let schema = output.schema();
let output: Result<Vec<RecordBatch>, _> = output.collect();
let output = concat_batches(&schema, &output?)?;
assert_eq!(input, output);
Modules§
Structs§
- Managed
Connection - Implementation of Connection.
- Managed
Database - Implementation of Database.
- Managed
Driver - Implementation of Driver.
- Managed
Statement - Implementation of Statement.