View Source Adbc.Connection (adbc v0.6.5)

Documentation for Adbc.Connection.

Connection are modelled as processes. They require an Adbc.Database to be started.

Summary

Functions

Returns a specification to start this module under a supervisor.

Get a binary (bytes) type option of the connection.

Gets the underlying driver of a connection process.

Get a float type option of the connection.

Get metadata about the database/driver.

Get an integer type option of the connection.

Get a hierarchical view of all catalogs, database schemas, tables, and columns.

Get a string type option of the connection.

Get a list of table types in the database.

Prepares the given query.

Runs the given query with params and statement_options.

Same as query/4 but raises an exception on error.

Runs the given query with params and pass the ArrowStream pointer to the given function.

Set option for the connection.

Starts a connection process.

Types

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

get_binary_option(conn, key)

View Source
@spec get_binary_option(pid(), atom() | String.t()) ::
  {:ok, binary()} | {:error, String.t()}

Get a binary (bytes) type option of the connection.

@spec get_driver(t()) :: {:ok, atom() | String.t()} | :error

Gets the underlying driver of a connection process.

Examples

ADBC.Connection.get_driver(conn)
#=> {:ok, :sqlite}
Link to this function

get_float_option(conn, key)

View Source
@spec get_float_option(pid(), atom() | String.t()) ::
  {:ok, float()} | {:error, String.t()}

Get a float type option of the connection.

Link to this function

get_info(conn, info_codes \\ [])

View Source
@spec get_info(t(), [non_neg_integer()]) ::
  {:ok, result_set()} | {:error, Exception.t()}

Get metadata about the database/driver.

The result is an Arrow dataset with the following schema:

Field NameField TypeNull Contstraint
info_nameuint32not null
info_valueINFO_SCHEMA

INFO_SCHEMA is a dense union with members:

Field NameType CodeField Type
string_value0utf8
bool_value1bool
int64_value2int64
int32_bitmask3int32
string_list4list<utf8>
int32_to_int32_list_map5map<int32, list<int32>>

Each metadatum is identified by an integer code. The recognized codes are defined as constants. Codes [0, 10_000) are reserved for ADBC usage. Drivers/vendors will ignore requests for unrecognized codes (the row will be omitted from the result).

Link to this function

get_integer_option(conn, key)

View Source
@spec get_integer_option(pid(), atom() | String.t()) ::
  {:ok, integer()} | {:error, String.t()}

Get an integer type option of the connection.

Link to this function

get_objects(conn, depth, opts \\ [])

View Source
@spec get_objects(
  t(),
  non_neg_integer(),
  catalog: String.t(),
  db_schema: String.t(),
  table_name: String.t(),
  table_type: [String.t()],
  column_name: String.t()
) :: {:ok, result_set()} | {:error, Exception.t()}

Get a hierarchical view of all catalogs, database schemas, tables, and columns.

The result is an Arrow dataset with the following schema:

Field NameField Type
catalog_nameutf8
catalog_db_schemaslist<DB_SCHEMA_SCHEMA>

DB_SCHEMA_SCHEMA is a Struct with fields:

Field NameField Type
db_schema_nameutf8
db_schema_tableslist<TABLE_SCHEMA>

TABLE_SCHEMA is a Struct with fields:

Field NameField TypeNull Contstraint
table_nameutf8not null
table_typeutf8not null
table_columnslist<COLUMN_SCHEMA>
table_constraintslist<CONSTRAINT_SCHEMA>

COLUMN_SCHEMA is a Struct with fields:

Field NameField TypeNull ContstraintComments
column_nameutf8not null
ordinal_positionint32(1)
remarksutf8(2)
xdbc_data_typeint16(3)
xdbc_type_nameutf8(3)
xdbc_column_sizeint32(3)
xdbc_decimal_digitsint16(3)
xdbc_num_prec_radixint16(3)
xdbc_nullableint16(3)
xdbc_column_defutf8(3)
xdbc_sql_data_typeint16(3)
xdbc_datetime_subint16(3)
xdbc_char_octet_lengthint32(3)
xdbc_is_nullableutf8(3)
xdbc_scope_catalogutf8(3)
xdbc_scope_schemautf8(3)
xdbc_scope_tableutf8(3)
xdbc_is_autoincrementbool(3)
xdbc_is_generatedcolumnbool(3)
  1. The column's ordinal position in the table (starting from 1).
  2. Database-specific description of the column.
  3. Optional value. Should be null if not supported by the driver. xdbc_ values are meant to provide JDBC/ODBC-compatible metadata in an agnostic manner.

CONSTRAINT_SCHEMA is a Struct with fields:

Field NameField TypeNull ContstraintComments
constraint_nameutf8
constraint_typeutf8not null(1)
constraint_column_nameslist<utf8>not null(2)
constraint_column_usagelist<USAGE_SCHEMA>(3)
  1. One of 'CHECK', 'FOREIGN KEY', 'PRIMARY KEY', or 'UNIQUE'.
  2. The columns on the current table that are constrained, in order.
  3. For FOREIGN KEY only, the referenced table and columns.

USAGE_SCHEMA is a Struct with fields:

Field NameField TypeNull Contstraint
fk_catalogutf8
fk_db_schemautf8
fk_tableutf8not null
fk_column_nameutf8not null
Link to this function

get_string_option(conn, key)

View Source
@spec get_string_option(pid(), atom() | String.t()) ::
  {:ok, String.t()} | {:error, String.t()}

Get a string type option of the connection.

@spec get_table_types(t()) :: {:ok, result_set()} | {:error, Exception.t()}

Get a list of table types in the database.

The result is an Arrow dataset with the following schema:

Field NameField TypeNull Contstraint
table_typeutf8not null
@spec prepare(t(), binary()) :: {:ok, reference()} | {:error, Exception.t()}

Prepares the given query.

Link to this function

query(conn, query, params \\ [], statement_options \\ [])

View Source
@spec query(t(), binary() | reference(), [term()], Keyword.t()) ::
  {:ok, result_set()} | {:error, Exception.t()}

Runs the given query with params and statement_options.

Link to this function

query!(conn, query, params \\ [], statement_options \\ [])

View Source
@spec query!(t(), binary() | reference(), [term()], Keyword.t()) :: result_set()

Same as query/4 but raises an exception on error.

Link to this function

query_pointer(conn, query, params \\ [], fun, statement_options \\ [])

View Source

Runs the given query with params and pass the ArrowStream pointer to the given function.

The pointer will point to a valid ArrowStream through the duration of the function. The function may call native code that consumes the ArrowStream accordingly.

Link to this function

set_option(conn, key, value)

View Source
@spec set_option(
  pid(),
  atom() | String.t(),
  atom() | {:binary, iodata()} | String.t() | number()
) :: :ok | {:error, String.t()}

Set option for the connection.

  • If value is an atom or a string, then corresponding string option will be set.
  • If value is a {:binary, iodata()}-tuple, then corresponding binary option will be set.
  • If value is an integer, then corresponding integer option will be set.
  • If value is a float, then corresponding float option will be set.

Starts a connection process.

Options

  • :database (required) - the database process to connect to

  • :process_options - the options to be given to the underlying process. See GenServer.start_link/3 for all options

Examples

Adbc.Connection.start_link(
  database: MyApp.DB,
  process_options: [name: MyApp.Conn]
)

In your supervision tree it would be started like this:

children = [
  {Adbc.Connection,
   database: MyApp.DB,
   process_options: [name: MyApp.Conn]}
]