impuls.db

class impuls.db.DBConnection

See impuls.DBConnection.

exception impuls.db.EmptyQueryResult

Bases: ValueError

EmptyQueryResult is an exception used when an SQL query returned an empty result, even tough the application expected at least one row.

class impuls.db.TypedQueryResult(db_cursor: Cursor, typ: Type[EntityT])

Bases: Generic[EntityT]

TypedQueryResult is an object returned by SQL queries, which automatically unmarshalls objects of the Impuls data model.

The interface of this object is otherwise similar to that of UntypedDataResult:

Apart from the .one()/.many()/.all() methods, TypedQueryResult support iteration.

TypedQueryResult should be closed after usage - this can be automatically done using with statements.

__enter__() Self
__exit__(*_: Any) None
__iter__() Self
__next__() EntityT
all() list[EntityT]

Returns all remaining rows of the query result.

close() None

Closes the resources used to access database results.

many() list[EntityT]

Returns an arbitrary number of rows from the query result, selected for optimum performance. If the returned list has no elements - there are no more rows in the result set.

one() EntityT | None

Returns the next row of the query result, or None if there are no more rows.

one_must(context: str) EntityT

Returns the next row of the query result, or raises EmptyQueryResult with the provided context if there are no more rows.

property rowcount: int

Read-only number of rows modified by INSERT, UPDATE or DELETE statement.

class impuls.db.UntypedQueryResult(db_cursor: Cursor)

Bases: object

UntypedQueryResult is an object returned by SQL queries, which returns results of unknown types.

Apart from the .one()/.many()/.all() methods, UntypedQueryResults support iteration.

UntypedQueryResult should be closed after usage - this can be automatically done using with statements.

__enter__() Self
__exit__(*_: Any) None
__iter__() Self
__next__() tuple[None | int | float | str, ...]
all() list[tuple[None | int | float | str, ...]]

Returns all remaining rows of the query result.

close() None

Closes the resources used to access database results.

many() list[tuple[None | int | float | str, ...]]

Returns an arbitrary number of rows from the query result, selected for optimum performance. If the returned list has no elements - there are no more rows in the result set.

one() tuple[None | int | float | str, ...] | None

Returns the next row of the query result, or None if there are no more rows.

one_must(context: str) tuple[None | int | float | str, ...]

Returns the next row of the query result, or raises EmptyQueryResult with the provided context if there are no more rows.

property rowcount: int

Read-only number of rows modified by INSERT, UPDATE or DELETE statement.