VirtualTableModule

public protocol VirtualTableModule

An SQLite virtual table module.

In the context of SQLite modules, init(arguments:create:) is conceptually equivalent to xConnect when create is false and to xCreate when create is true. That is, create is true if the module instance is being constructed as part of a CREATE VIRTUAL TABLE statement.

deinit is conceptually equivalent to xDisconnect while destroy is conceptually equivalent to xDestroy. destroy() is invoked by a DROP TABLE statement.

  • Opens a connection to an SQLite virtual table module.

    Throws

    SQLiteError if the module could not be created

    Declaration

    Swift

    init(database: Database, arguments: [String], create: Bool) throws

    Parameters

    database

    The database to which this virtual table module is being added.

    arguments

    The arguments used to create the virtual table module. The first argument is the name of the module being invoked. The second argument is the name of the database in which the virtual table is being created. The third argument is the name of the new virtual table. Any additional arguments are those passed to the module name in the CREATE VIRTUAL TABLE statement.

    create

    Whether the virtual table module is being initialized as the result of a CREATE VIRTUAL TABLE statement and should create any persistent state.

  • The options supported by this virtual table module

    Declaration

    Swift

    var options: Database.VirtualTableModuleOptions { get }
  • The SQL CREATE TABLE statement used to tell SQLite about the virtual table’s columns and datatypes.

    Note

    The name of the table and any constraints are ignored.

    Declaration

    Swift

    var declaration: String { get }
  • Destroys any persistent state associated with the virtual table module

    Note

    This is only called as the result of a DROP TABLE statement.

    Declaration

    Swift

    func destroy() throws
  • Determines the query plan to use for a given query

    Throws

    SQLiteError if an error occurs

    Declaration

    Swift

    func bestIndex(_ indexInfo: inout sqlite3_index_info) throws -> VirtualTableModuleBestIndexResult

    Parameters

    indexInfo

    An sqlite3_index_info struct containing information on the query

    Return Value

    .ok on success or .constraint if the configuration of unusable flags in indexInfo cannot result in a usable query plan

  • Opens and returns a cursor for the virtual table

    Throws

    SQLiteError error if the cursor could not be created

    Declaration

    Swift

    func openCursor() throws -> VirtualTableCursor

    Return Value

    An initalized cursor for the virtual table