shillelagh.backends.apsw package

Subpackages

Submodules

shillelagh.backends.apsw.db module

A DB API 2.0 wrapper for APSW.

shillelagh.backends.apsw.db.Binary(string: str) bytes[source]

constructs an object capable of holding a binary (long) string value.

exception shillelagh.backends.apsw.db.DataError[source]

Bases: DatabaseError

Errors that are due to problems with the processed data.

Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range, etc. It must be a subclass of DatabaseError.

exception shillelagh.backends.apsw.db.DatabaseError[source]

Bases: Error

Errors that are related to the database.

Exception raised for errors that are related to the database. It must be a subclass of Error.

shillelagh.backends.apsw.db.Date(year: int, month: int, day: int) date[source]

Constructs an object holding a date value.

shillelagh.backends.apsw.db.DateFromTicks(ticks: int) date[source]

Constructs an object holding a date value from the given ticks value.

Ticks should be in number of seconds since the epoch.

exception shillelagh.backends.apsw.db.Error[source]

Bases: Exception

Base class of all other error exceptions.

Exception that is the base class of all other error exceptions. You can use this to catch all errors with one single except statement. Warnings are not considered errors and thus should not use this class as base. It must be a subclass of the Python StandardError (defined in the module exceptions).

exception shillelagh.backends.apsw.db.IntegrityError[source]

Bases: DatabaseError

Raised when the relational integrity of the database is affected.

Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails. It must be a subclass of DatabaseError.

exception shillelagh.backends.apsw.db.InterfaceError[source]

Bases: Error

Errors that are related to the database interface.

Exception raised for errors that are related to the database interface rather than the database itself. It must be a subclass of Error.

exception shillelagh.backends.apsw.db.InternalError[source]

Bases: DatabaseError

Raised when the database encounters an internal error.

Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync, etc. It must be a subclass of DatabaseError.

exception shillelagh.backends.apsw.db.OperationalError[source]

Bases: DatabaseError

Errors that are related to the database’s operation.

Exception raised for errors that are related to the database’s operation and not necessarily under the control of the programmer, e.g. an unexpected disconnect occurs, the data source name is not found, a transaction could not be processed, a memory allocation error occurred during processing, etc. It must be a subclass of DatabaseError.

shillelagh.backends.apsw.db.Time(hour: int, minute: int, second: int) time[source]

Constructs an object holding a time value.

shillelagh.backends.apsw.db.TimeFromTicks(ticks: int) time[source]

Constructs an object holding a time value from the given ticks value.

Ticks should be in number of seconds since the epoch.

shillelagh.backends.apsw.db.Timestamp(year: int, month: int, day: int, hour: int, minute: int, second: int) datetime[source]

Constructs an object holding a timestamp value.

shillelagh.backends.apsw.db.TimestampFromTicks(ticks: int) datetime[source]

Constructs an object holding a timestamp value from the given ticks value.

Ticks should be in number of seconds since the epoch.

exception shillelagh.backends.apsw.db.Warning[source]

Bases: Exception

Important warnings like data truncations while inserting.

Exception raised for important warnings like data truncations while inserting, etc. It must be a subclass of the Python StandardError (defined in the module exceptions).

shillelagh.backends.apsw.vt module

A SQLite virtual table.

This module implements a SQLite virtual table that delegates data requests to adapters. The main goal is to make the interface easier to use, to simplify the work of writing new adapters.

class shillelagh.backends.apsw.vt.VTCursor(adapter: Adapter)[source]

Bases: object

An object for iterating over a table.

Close() None[source]

This is the destructor for the cursor.

Column(col) Any[source]

Requests the value of the specified column number of the current row.

Eof() bool[source]

Called to ask if we are at the end of the table.

Filter(indexnumber: int, indexname: str, constraintargs: List[Any]) None[source]

Filter and sort data according to constraints.

This method converts the indexname (containing which columns to filter and the order to sort the results) and constraintargs into a pair of bounds and order. These are then passed to the get_rows method of the adapter, to filter and sort the data.

Next() None[source]

Move the cursor to the next row.

Rowid() int[source]

Return the current rowid.

class shillelagh.backends.apsw.vt.VTModule(adapter: Type[Adapter])[source]

Bases: object

A module used to create SQLite virtual tables.

This implementation delegates data requests to a Shillelagh adapter, simplifying the work needed to support new data sources.

Connect(connection: Connection, modulename: str, dbname: str, tablename: str, *args: str) Tuple[str, VTTable]

Called when a table is first created on a connection.

Create(connection: Connection, modulename: str, dbname: str, tablename: str, *args: str) Tuple[str, VTTable][source]

Called when a table is first created on a connection.

class shillelagh.backends.apsw.vt.VTTable(adapter: Adapter)[source]

Bases: object

A SQLite virtual table.

The VTTable object contains knowledge of the indices, makes cursors and can perform transactions.

A virtual table is structured as a series of rows, each of which has the same columns. The value in a column must be one of the 5 supported types, but the type can be different between rows for the same column. The virtual table routines identify the columns by number, starting at zero.

Each row has a unique 64 bit integer rowid with the Cursor routines operating on this number, as well as some of the Table routines such as UpdateChangeRow.

BestIndex(constraints: List[Tuple[int, int]], orderbys: List[Tuple[int, bool]]) Tuple[List[None | int | Tuple[int, bool]], int, str, bool, float][source]

Build an index for a given set of constraints and order bys.

The purpose of this method is to ask if you have the ability to determine if a row meets certain constraints that doesn’t involve visiting every row.

BestIndexObject(index_info: IndexInfo) bool[source]

Alternative to BestIndex that allows returning only selected columns.

Destroy() None

The opposite of VTModule.Connect().

This method is called when a reference to a virtual table is no longer used, but VTTable.Destroy() will be called when the table is no longer used.

Disconnect() None[source]

The opposite of VTModule.Connect().

This method is called when a reference to a virtual table is no longer used, but VTTable.Destroy() will be called when the table is no longer used.

Open() VTCursor[source]

Returns a cursor object.

UpdateChangeRow(rowid: int, newrowid: int, fields: Tuple[Any, ...]) None[source]

Change an existing row.

Note that the row ID can be modified.

UpdateDeleteRow(rowid: int) None[source]

Delete the row with the specified rowid.

UpdateInsertRow(rowid: int | None, fields: Tuple[Any, ...]) int[source]

Insert a row with the specified rowid.

get_create_table(tablename: str) str[source]

Return the table’s CREATE TABLE statement.

shillelagh.backends.apsw.vt.convert_rows_from_sqlite(columns: Dict[str, Field], rows: Iterator[Dict[str, None | int | float | str | bytes]]) Iterator[Dict[str, Any]][source]

Convert values from SQLite types to native Python types.

Native Python types like datetime.datetime are not supported by SQLite; instead we need to cast them to strings or numbers. We use the original fields to handle the conversion (not the adapter fields).

shillelagh.backends.apsw.vt.convert_rows_to_sqlite(columns: Dict[str, Field], rows: Iterator[Dict[str, Any]]) Iterator[Dict[str, None | int | float | str | bytes]][source]

Convert values from native Python types to SQLite types.

Native Python types like datetime.datetime are not supported by SQLite; instead we need to cast them to strings or numbers. We use the original fields to handle the conversion (not the adapter fields).

shillelagh.backends.apsw.vt.get_all_bounds(indexes: List[Tuple[int, int]], constraintargs: List[Any], columns: Dict[str, Field]) DefaultDict[str, Set[Tuple[Operator, Any]]][source]

Convert indexes and constraints to operations on each column.

shillelagh.backends.apsw.vt.get_bounds(columns: Dict[str, Field], all_bounds: DefaultDict[str, Set[Tuple[Operator, Any]]]) Dict[str, Filter][source]

Combine all filters that apply to each column.

shillelagh.backends.apsw.vt.get_limit_offset(indexes: List[Tuple[int, int]], constraintargs: List[Any]) Tuple[int | None, int | None][source]

Extract limit and offset.

shillelagh.backends.apsw.vt.get_order(orderbys: List[Tuple[int, bool]], column_names: List[str]) List[Tuple[str, Literal[Order.ASCENDING] | Literal[Order.DESCENDING]]][source]

Return a list of column names and sort order from a SQLite orderbys.

Module contents