Skip to content

plpipes.database.sqlext#

This module provides SQLAlchemy extensions for performing tasks not natively supported by the SQLAlchemy ORM. It includes constructs for creating and dropping tables and views, inserting data from queries, and handling subqueries.

AsSubquery #

Bases: FromClause

Class for handling subqueries.

Source code in src\plpipes\database\sqlext.py
class AsSubquery(FromClause):
    """
    Class for handling subqueries.
    """
    inherit_cache = False

    def __init__(self, txt):
        """
        Initializes a subquery.

        :param txt: The text of the subquery.
        """
        self._txt = txt

__init__(txt) #

Initializes a subquery.

:param txt: The text of the subquery.

Source code in src\plpipes\database\sqlext.py
def __init__(self, txt):
    """
    Initializes a subquery.

    :param txt: The text of the subquery.
    """
    self._txt = txt

CreateTableAs #

Bases: _CreateSomethingAs

Class for creating a table from a select statement.

Source code in src\plpipes\database\sqlext.py
class CreateTableAs(_CreateSomethingAs):
    """
    Class for creating a table from a select statement.
    """
    inherit_cache = True

    def __init__(self, *args, **kwargs):
        """
        Initializes the creation of a table.
        """
        super().__init__("TABLE", *args, **kwargs)

__init__(*args, **kwargs) #

Initializes the creation of a table.

Source code in src\plpipes\database\sqlext.py
def __init__(self, *args, **kwargs):
    """
    Initializes the creation of a table.
    """
    super().__init__("TABLE", *args, **kwargs)

CreateViewAs #

Bases: _CreateSomethingAs

Class for creating a view from a select statement.

Source code in src\plpipes\database\sqlext.py
class CreateViewAs(_CreateSomethingAs):
    """
    Class for creating a view from a select statement.
    """
    inherit_cache = True

    def __init__(self, *args, **kwargs):
        """
        Initializes the creation of a view.
        """
        super().__init__("VIEW", *args, **kwargs)

__init__(*args, **kwargs) #

Initializes the creation of a view.

Source code in src\plpipes\database\sqlext.py
def __init__(self, *args, **kwargs):
    """
    Initializes the creation of a view.
    """
    super().__init__("VIEW", *args, **kwargs)

DropTable #

Bases: _DropSomething

Class for dropping a table.

Source code in src\plpipes\database\sqlext.py
class DropTable(_DropSomething):
    """
    Class for dropping a table.
    """
    inherit_cache = False

    def __init__(self, *args, **kwargs):
        """
        Initializes the drop operation for a table.
        """
        super().__init__("TABLE", *args, **kwargs)

__init__(*args, **kwargs) #

Initializes the drop operation for a table.

Source code in src\plpipes\database\sqlext.py
def __init__(self, *args, **kwargs):
    """
    Initializes the drop operation for a table.
    """
    super().__init__("TABLE", *args, **kwargs)

DropView #

Bases: _DropSomething

Class for dropping a view.

Source code in src\plpipes\database\sqlext.py
class DropView(_DropSomething):
    """
    Class for dropping a view.
    """
    inherit_cache = False

    def __init__(self, *args, **kwargs):
        """
        Initializes the drop operation for a view.
        """
        super().__init__("VIEW", *args, **kwargs)

__init__(*args, **kwargs) #

Initializes the drop operation for a view.

Source code in src\plpipes\database\sqlext.py
def __init__(self, *args, **kwargs):
    """
    Initializes the drop operation for a view.
    """
    super().__init__("VIEW", *args, **kwargs)

InsertIntoTableFromQuery #

Bases: Executable, ClauseElement

Class for inserting data into a table from a select statement.

Source code in src\plpipes\database\sqlext.py
class InsertIntoTableFromQuery(Executable, ClauseElement):
    """
    Class for inserting data into a table from a select statement.
    """
    inherit_cache = True

    def __init__(self, table_name, select):
        """
        Initializes the insert operation.

        :param table_name: Name of the table to insert into.
        :param select: Select statement providing data to insert.
        """
        self._table_name = table_name
        self._select = select

__init__(table_name, select) #

Initializes the insert operation.

:param table_name: Name of the table to insert into. :param select: Select statement providing data to insert.

Source code in src\plpipes\database\sqlext.py
def __init__(self, table_name, select):
    """
    Initializes the insert operation.

    :param table_name: Name of the table to insert into.
    :param select: Select statement providing data to insert.
    """
    self._table_name = table_name
    self._select = select

Wrap(str_or_something) #

Wraps a string or other expression into a SQLAlchemy text object.

:param str_or_something: The string or expression to wrap. :return: A SQLAlchemy text object or the original expression.

Source code in src\plpipes\database\sqlext.py
def Wrap(str_or_something):
    """
    Wraps a string or other expression into a SQLAlchemy text object.

    :param str_or_something: The string or expression to wrap.
    :return: A SQLAlchemy text object or the original expression.
    """
    if isinstance(str_or_something, str):
        return sqlalchemy.sql.text(str_or_something)
    return str_or_something