rwskit.sqlalchemy

Utilities for working with SqlAlchemy.

Attributes

log

B

A type extending DeclarativeBase.

SqlOperator

The supported SQL operators for use in an SqlBinaryExpression.

Classes

BaseModel

A base class for creating declarative SqlAlchemy models from.

SqlBinaryExpression

A class that represents the basic binary expression for an SQL column.

SqlSelectionCriteria

A class that represents a conjunction of SqlBinaryExpression.

Module Contents

rwskit.sqlalchemy.log[source]
rwskit.sqlalchemy.B[source]

A type extending DeclarativeBase.

rwskit.sqlalchemy.SqlOperator[source]

The supported SQL operators for use in an SqlBinaryExpression.

class rwskit.sqlalchemy.BaseModel[source]

Bases: sqlalchemy.orm.DeclarativeBase

A base class for creating declarative SqlAlchemy models from.

This class provides functionality for finding any model derived from this clas by their table name.

__abstract__ = True[source]
__tablename__()[source]
classmethod find_by_table_name(table_name: str) Type[BaseModel] | None[source]

Find a model derived from this class by its table name.

Parameters:

table_name (str) – The name of the table whose model class you want to find.

Returns:

Returns the model class if the table is found, otherwise None.

Return type:

Type[FindByNameBase], optional

class rwskit.sqlalchemy.SqlBinaryExpression[source]

Bases: rwskit.config.YamlConfig

A class that represents the basic binary expression for an SQL column.

column: str[source]

The column name.

operator: SqlOperator[source]

The operator to compare the column and value with.

value: Any[source]

The value used as a comparison.

__post_init__()[source]
__call__(model_or_table: Type[B] | sqlalchemy.Table) sqlalchemy.BinaryExpression[source]
to_expression(model_or_table: Type[B] | sqlalchemy.Table) sqlalchemy.BinaryExpression[source]

Return a clause that can be used with an SqlAlchemy where statement.

Parameters:

model_or_table (sqlalchemy.Table) – The table object that contains the column.

Returns:

The corresponding SqlAlchemy binary expression.

Return type:

BinaryExpression

class rwskit.sqlalchemy.SqlSelectionCriteria[source]

Bases: rwskit.config.YamlConfig

A class that represents a conjunction of SqlBinaryExpression.

expressions: list[SqlBinaryExpression][source]

The list of binary expressions that will be used to filter the query.

__post_init__()[source]
to_conjunction(table: sqlalchemy.Table) sqlalchemy.BinaryExpression | sqlalchemy.BooleanClauseList[source]

Return a conjunction of binary expressions that can be used with an SqlAlchemy where statement.