ExArrow.ADBC.DriverHelper (ex_arrow v0.4.0)

View Source

Convenience helpers for using ExArrow's ADBC APIs together with the adbc package.

This module is entirely optional:

Important: ExArrow's ADBC layer uses the C driver manager and expects a loadable shared library (e.g. libadbc_driver_sqlite.so). The adbc Hex package has its own process-based Database/Connection and native stack; its drivers are not necessarily installed in a form the C driver manager can load. So ensure_driver_and_open/2 may return {:error, _} even after Adbc.download_driver/1 succeeds. In that case, use a standalone ADBC C driver (see the project's livebook/INSTALL_ADBC_DRIVER.md or docs).

For tests, you can inject the download module via application config :ex_arrow, :adbc_download_module (default: Adbc).

Summary

Functions

Ensures the given ADBC driver is available (using Adbc.download_driver/1 when the :adbc package is present), then opens a database via ExArrow.ADBC.Database.open/1. Returns {:error, reason} if the download fails or if Database.open/1 fails.

Functions

ensure_driver_and_open(driver_key, uri)

@spec ensure_driver_and_open(atom(), String.t()) ::
  {:ok, ExArrow.ADBC.Database.t()} | {:error, term()}

Ensures the given ADBC driver is available (using Adbc.download_driver/1 when the :adbc package is present), then opens a database via ExArrow.ADBC.Database.open/1. Returns {:error, reason} if the download fails or if Database.open/1 fails.

This is a convenience around the common pattern:

  • use adbc to manage/download drivers (e.g. :sqlite, :postgresql)
  • open the database with ExArrow so you get Arrow streams from execute/1

Examples

# Ensure the SQLite driver is available (if :adbc is in your deps)
# and open an in-memory database via ExArrow:
{:ok, db} =
  ExArrow.ADBC.DriverHelper.ensure_driver_and_open(:sqlite, ":memory:")

{:ok, conn} = ExArrow.ADBC.Connection.open(db)
{:ok, stmt} = ExArrow.ADBC.Statement.new(conn, "SELECT 1 AS n")
{:ok, stream} = ExArrow.ADBC.Statement.execute(stmt)

If the :adbc package is not installed, this function still works; it simply skips the download step and calls ExArrow.ADBC.Database.open/1 with the inferred options.