[go: up one dir, main page]

Connection

Trait Connection 

Source
pub trait Connection: Optionable<Option = OptionConnection> {
    type StatementType: Statement;

    // Required methods
    fn new_statement(&mut self) -> Result<Self::StatementType>;
    fn cancel(&mut self) -> Result<()>;
    fn get_info(
        &self,
        codes: Option<HashSet<InfoCode>>,
    ) -> Result<impl RecordBatchReader + Send>;
    fn get_objects(
        &self,
        depth: ObjectDepth,
        catalog: Option<&str>,
        db_schema: Option<&str>,
        table_name: Option<&str>,
        table_type: Option<Vec<&str>>,
        column_name: Option<&str>,
    ) -> Result<impl RecordBatchReader + Send>;
    fn get_table_schema(
        &self,
        catalog: Option<&str>,
        db_schema: Option<&str>,
        table_name: &str,
    ) -> Result<Schema>;
    fn get_table_types(&self) -> Result<impl RecordBatchReader + Send>;
    fn get_statistic_names(&self) -> Result<impl RecordBatchReader + Send>;
    fn get_statistics(
        &self,
        catalog: Option<&str>,
        db_schema: Option<&str>,
        table_name: Option<&str>,
        approximate: bool,
    ) -> Result<impl RecordBatchReader + Send>;
    fn commit(&mut self) -> Result<()>;
    fn rollback(&mut self) -> Result<()>;
    fn read_partition(
        &self,
        partition: impl AsRef<[u8]>,
    ) -> Result<impl RecordBatchReader + Send>;
}
Expand description

A handle to an ADBC connection.

Connections provide methods for query execution, managing prepared statements, using transactions, and so on.

§Autocommit

Connections should start in autocommit mode. They can be moved out by setting options::OptionConnection::AutoCommit to “false”. Turning off autocommit allows customizing the isolation level.

Required Associated Types§

Required Methods§

Source

fn new_statement(&mut self) -> Result<Self::StatementType>

Allocate and initialize a new statement.

Source

fn cancel(&mut self) -> Result<()>

Cancel the in-progress operation on a connection.

Source

fn get_info( &self, codes: Option<HashSet<InfoCode>>, ) -> Result<impl RecordBatchReader + Send>

Get metadata about the database/driver.

§Arguments
  • codes - Requested metadata. If None, retrieve all available metadata.
§Result

The result is an Arrow dataset with the following schema:

Field NameField Type
info_nameuint32 not null
info_valueINFO_SCHEMA

INFO_SCHEMA is a dense union with members:

Field Name (Type Code)Field Type
string_value (0)utf8
bool_value (1)bool
int64_value (2)int64
int32_bitmask (3)int32
string_list (4)list<utf8>
int32_to_int32_list_map (5)map<int32, list<int32>>
Source

fn get_objects( &self, depth: ObjectDepth, catalog: Option<&str>, db_schema: Option<&str>, table_name: Option<&str>, table_type: Option<Vec<&str>>, column_name: Option<&str>, ) -> Result<impl RecordBatchReader + Send>

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

§Arguments
  • depth - The level of nesting to query.
  • catalog - Only show tables in the given catalog. If None, do not filter by catalog. If an empty string, only show tables without a catalog. May be a search pattern.
  • db_schema - Only show tables in the given database schema. If None, do not filter by database schema. If an empty string, only show tables without a database schema. May be a search pattern.
  • table_name - Only show tables with the given name. If None, do not filter by name. May be a search pattern.
  • table_type - Only show tables matching one of the given table types. If None, show tables of any type. Valid table types can be fetched from Connection::get_table_types.
  • column_name - Only show columns with the given name. If None, do not filter by name. May be a search pattern..
§Result

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 Type
table_nameutf8 not null
table_typeutf8 not null
table_columnslist<COLUMN_SCHEMA>
table_constraintslist<CONSTRAINT_SCHEMA>

COLUMN_SCHEMA is a Struct with fields:

Field NameField TypeComments
column_nameutf8 not 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 TypeComments
constraint_nameutf8
constraint_typeutf8 not 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 Type
fk_catalogutf8
fk_db_schemautf8
fk_tableutf8 not null
fk_column_nameutf8 not null
Source

fn get_table_schema( &self, catalog: Option<&str>, db_schema: Option<&str>, table_name: &str, ) -> Result<Schema>

Get the Arrow schema of a table.

§Arguments
  • catalog - The catalog (or None if not applicable).
  • db_schema - The database schema (or None if not applicable).
  • table_name - The table name.
Source

fn get_table_types(&self) -> Result<impl RecordBatchReader + Send>

Get a list of table types in the database.

§Result

The result is an Arrow dataset with the following schema:

Field NameField Type
table_typeutf8 not null
Source

fn get_statistic_names(&self) -> Result<impl RecordBatchReader + Send>

Get the names of statistics specific to this driver.

§Result

The result is an Arrow dataset with the following schema:

Field NameField Type
statistic_nameutf8 not null
statistic_keyint16 not null
§Since

ADBC API revision 1.1.0

Source

fn get_statistics( &self, catalog: Option<&str>, db_schema: Option<&str>, table_name: Option<&str>, approximate: bool, ) -> Result<impl RecordBatchReader + Send>

Get statistics about the data distribution of table(s).

§Arguments
  • catalog - The catalog (or None if not applicable). May be a search pattern.
  • db_schema - The database schema (or None if not applicable). May be a search pattern
  • table_name - The table name (or None if not applicable). May be a search pattern
  • approximate - If false, request exact values of statistics, else allow for best-effort, approximate, or cached values. The database may return approximate values regardless, as indicated in the result. Requesting exact values may be expensive or unsupported.
§Result

The result is an Arrow dataset with the following schema:

Field NameField Type
catalog_nameutf8
catalog_db_schemaslist<DB_SCHEMA_SCHEMA> not null

DB_SCHEMA_SCHEMA is a Struct with fields:

Field NameField Type
db_schema_nameutf8
db_schema_statisticslist<STATISTICS_SCHEMA> not null

STATISTICS_SCHEMA is a Struct with fields:

Field NameField TypeComments
table_nameutf8 not null
column_nameutf8(1)
statistic_keyint16 not null(2)
statistic_valueVALUE_SCHEMA not null
statistic_is_approximatebool not null(3)
  1. If null, then the statistic applies to the entire table.
  2. A dictionary-encoded statistic name (although we do not use the Arrow dictionary type). Values in [0, 1024) are reserved for ADBC. Other values are for implementation-specific statistics. For the definitions of predefined statistic types, see options::Statistics. To get driver-specific statistic names, use Connection::get_statistic_names.
  3. If true, then the value is approximate or best-effort.

VALUE_SCHEMA is a dense union with members:

Field NameField Type
int64int64
uint64uint64
float64float64
binarybinary
§Since

ADBC API revision 1.1.0

Source

fn commit(&mut self) -> Result<()>

Commit any pending transactions. Only used if autocommit is disabled.

Behavior is undefined if this is mixed with SQL transaction statements.

Source

fn rollback(&mut self) -> Result<()>

Roll back any pending transactions. Only used if autocommit is disabled.

Behavior is undefined if this is mixed with SQL transaction statements.

Source

fn read_partition( &self, partition: impl AsRef<[u8]>, ) -> Result<impl RecordBatchReader + Send>

Retrieve a given partition of data.

A partition can be retrieved from Statement::execute_partitions.

§Arguments
  • partition - The partition descriptor.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§