rwskit.sqlalchemy ================= .. py:module:: rwskit.sqlalchemy .. autoapi-nested-parse:: Utilities for working with SqlAlchemy. Attributes ---------- .. autoapisummary:: rwskit.sqlalchemy.log rwskit.sqlalchemy.B rwskit.sqlalchemy.SqlOperator Classes ------- .. autoapisummary:: rwskit.sqlalchemy.BaseModel rwskit.sqlalchemy.SqlBinaryExpression rwskit.sqlalchemy.SqlSelectionCriteria Module Contents --------------- .. py:data:: log .. py:data:: B A type extending :class:`~sqlalchemy.orm.DeclarativeBase`. .. py:data:: SqlOperator The supported SQL operators for use in an :class:`SqlBinaryExpression`. .. py:class:: BaseModel Bases: :py:obj:`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. .. py:attribute:: __abstract__ :value: True .. py:method:: __tablename__() .. py:method:: find_by_table_name(table_name: str) -> Optional[Type[BaseModel]] :classmethod: Find a model derived from this class by its table name. :param table_name: The name of the table whose model class you want to find. :type table_name: str :returns: Returns the model class if the table is found, otherwise ``None``. :rtype: Type[FindByNameBase], optional .. py:class:: SqlBinaryExpression Bases: :py:obj:`rwskit.config.YamlConfig` A class that represents the basic binary expression for an SQL column. .. py:attribute:: column :type: str The column name. .. py:attribute:: operator :type: SqlOperator The operator to compare the ``column`` and ``value`` with. .. py:attribute:: value :type: Any The value used as a comparison. .. py:method:: __post_init__() .. py:method:: __call__(model_or_table: Type[B] | sqlalchemy.Table) -> sqlalchemy.BinaryExpression .. py:method:: to_expression(model_or_table: Type[B] | sqlalchemy.Table) -> sqlalchemy.BinaryExpression Return a clause that can be used with an SqlAlchemy ``where`` statement. :param model_or_table: The table object that contains the column. :type model_or_table: sqlalchemy.Table :returns: The corresponding SqlAlchemy binary expression. :rtype: BinaryExpression .. py:class:: SqlSelectionCriteria Bases: :py:obj:`rwskit.config.YamlConfig` A class that represents a conjunction of SqlBinaryExpression. .. py:attribute:: expressions :type: list[SqlBinaryExpression] The list of binary expressions that will be used to filter the query. .. py:method:: __post_init__() .. py:method:: to_conjunction(table: sqlalchemy.Table) -> sqlalchemy.BinaryExpression | sqlalchemy.BooleanClauseList Return a conjunction of binary expressions that can be used with an SqlAlchemy ``where`` statement.