VTab

Trait VTab 

Source
pub trait VTab<'vtab> {
    type Aux: 'vtab;
    type Cursor: VTabCursor<'vtab>;

    // Required methods
    fn connect(
        db: &'vtab VTabConnection,
        aux: &'vtab Self::Aux,
        args: &[&str],
    ) -> Result<(String, Self)>
       where Self: Sized;
    fn best_index(&'vtab self, index_info: &mut IndexInfo) -> Result<()>;
    fn open(&'vtab self) -> Result<Self::Cursor>;

    // Provided method
    fn disconnect(&mut self) -> Result<()> { ... }
}
Expand description

A virtual table.

This trait defines functionality required by all virtual tables. A read-only, eponymous-only virtual table (e.g. a table-valued function) can implement only this trait.

Required Associated Types§

Source

type Aux: 'vtab

Additional data associated with the virtual table module.

When registering the module with Connection::create_module, additional data can be passed as a parameter. This data will be passed to connect and create. It can be used for any purpose.

Source

type Cursor: VTabCursor<'vtab>

Cursor implementation for this virtual table.

Required Methods§

Source

fn connect( db: &'vtab VTabConnection, aux: &'vtab Self::Aux, args: &[&str], ) -> Result<(String, Self)>
where Self: Sized,

Corresponds to xConnect.

This method is called called when connecting to an existing virtual table, either because it was previously created with CREATE VIRTUAL TABLE (see CreateVTab::create), or because it is an eponymous virtual table.

This method must return a valid CREATE TABLE statement as a String, along with a configured table instance. Additionally, all virtual tables are recommended to set a risk level using VTabConnection::set_risk_level.

The virtual table implementation will return an error if any of the arguments contain invalid UTF-8.

Source

fn best_index(&'vtab self, index_info: &mut IndexInfo) -> Result<()>

Corrresponds to xBestIndex.

This method is called when SQLite is planning to query a virtual table. See IndexInfo for details.

If this method returns Err(SQLITE_CONSTRAINT), that does not indicate an error. Rather, it indicates that the particular combination of input parameters specified is insufficient for the virtual table to do its job. This is logically the same as setting the estimated_cost to infinity. If every call to best_index for a particular query plan returns this error, that means there is no way for the virtual table to be safely used, and the SQLite call will fail with a “no query solution” error.

Source

fn open(&'vtab self) -> Result<Self::Cursor>

Create an uninitialized query.

Provided Methods§

Source

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

Corresponds to xDisconnect. This method is called when the database connection is being closed. The implementation should not remove the underlying data, but it should release any resources associated with the virtual table implementation. This method is the inverse of Self::connect.

After invoking this method, the virtual table implementation is immediately dropped. The default implementation of this method simply returns Ok.

Implementors§