module documentation

High level utilities which build upon other modules here.

Class ClauseAdapter Clones and modifies clauses based on column correspondence.
Class ColumnAdapter Extends ClauseAdapter with extra utility functions.
Function adapt_criterion_to_null given criterion containing bind params, convert selected elements to IS NULL.
Function bind_values Return an ordered list of "bound" values in the given clause.
Function clause_is_present Given a target clause and a second to search within, return True if the target is plainly present in the search without any subqueries or aliases involved.
Function criterion_as_pairs traverse an expression and locate binary criterion pairs.
Function expand_column_list_from_order_by Given the columns clause and ORDER BY of a selectable, return a list of column expressions that can be added to the collist corresponding to the ORDER BY, without repeating those already in the collist.
Function extract_first_column_annotation Undocumented
Function find_join_source Given a list of FROM clauses and a selectable, return the first index and element from the list of clauses which can be joined against the selectable. returns None, None if no match is found.
Function find_left_clause_that_matches_given Given a list of FROM clauses and a selectable, return the indexes from the list of clauses which is derived from the selectable.
Function find_left_clause_to_join_from Given a list of FROM clauses, a selectable, and optional ON clause, return a list of integer indexes from the clauses list indicating the clauses that can be joined from.
Function find_tables locate Table objects within the given expression.
Function join_condition Create a join condition between two tables or selectables.
Function reduce_columns given a list of columns, return a 'reduced' set based on natural equivalents.
Function selectables_overlap Return True if left/right have some overlapping selectable
Function splice_joins Undocumented
Function surface_selectables Undocumented
Function surface_selectables_only Undocumented
Function tables_from_leftmost Undocumented
Function unwrap_label_reference Undocumented
Function unwrap_order_by Break up an 'order by' expression into individual column-expressions, without DESC/ASC/NULLS FIRST/NULLS LAST
Function visit_binary_product Produce a traversal of the given expression, delivering column comparisons to the given function.
Class _ColumnLookup Undocumented
Class _long_statement Undocumented
Class _repr_base Undocumented
Class _repr_params Provide a string view of bound parameters.
Class _repr_row Provide a string view of a row.
Function _make_slice Compute LIMIT/OFFSET in terms of slice start/end
Function _offset_or_limit_clause Convert the given value to an "offset or limit" clause.
Function _offset_or_limit_clause_asint_if_possible Return the offset or limit clause as a simple integer if possible, else return the clause.
Function _quote_ddl_expr Undocumented
Function _repr_single_value Undocumented
Type Variable _CE Undocumented
def adapt_criterion_to_null(crit: _CE, nulls: Collection[Any]) -> _CE: (source)

given criterion containing bind params, convert selected elements to IS NULL.

def bind_values(clause): (source)

Return an ordered list of "bound" values in the given clause. E.g.:: >>> expr = and_( ... table.c.foo==5, table.c.foo==7 ... ) >>> bind_values(expr) [5, 7]

def clause_is_present(clause, search): (source)

Given a target clause and a second to search within, return True if the target is plainly present in the search without any subqueries or aliases involved. Basically descends through Joins.

def criterion_as_pairs(expression, consider_as_foreign_keys=None, consider_as_referenced_keys=None, any_operator=False): (source)

traverse an expression and locate binary criterion pairs.

def expand_column_list_from_order_by(collist, order_by): (source)

Given the columns clause and ORDER BY of a selectable, return a list of column expressions that can be added to the collist corresponding to the ORDER BY, without repeating those already in the collist.

def extract_first_column_annotation(column, annotation_name): (source)

Undocumented

def find_join_source(clauses: List[FromClause], join_to: FromClause) -> List[int]: (source)

Given a list of FROM clauses and a selectable, return the first index and element from the list of clauses which can be joined against the selectable. returns None, None if no match is found. e.g.:: clause1 = table1.join(table2) clause2 = table4.join(table5) join_to = table2.join(table3) find_join_source([clause1, clause2], join_to) == clause1

def find_left_clause_that_matches_given(clauses: Sequence[FromClause], join_from: FromClause) -> List[int]: (source)

Given a list of FROM clauses and a selectable, return the indexes from the list of clauses which is derived from the selectable.

def find_left_clause_to_join_from(clauses: Sequence[FromClause], join_to: _JoinTargetElement, onclause: Optional[ColumnElement[Any]]) -> List[int]: (source)

Given a list of FROM clauses, a selectable, and optional ON clause, return a list of integer indexes from the clauses list indicating the clauses that can be joined from. The presence of an "onclause" indicates that at least one clause can definitely be joined from; if the list of clauses is of length one and the onclause is given, returns that index. If the list of clauses is more than length one, and the onclause is given, attempts to locate which clauses contain the same columns.

def find_tables(clause: ClauseElement, *, check_columns: bool = False, include_aliases: bool = False, include_joins: bool = False, include_selects: bool = False, include_crud: bool = False) -> List[TableClause]: (source)

locate Table objects within the given expression.

def join_condition(a: FromClause, b: FromClause, a_subset: Optional[FromClause] = None, consider_as_foreign_keys: Optional[AbstractSet[ColumnClause[Any]]] = None) -> ColumnElement[bool]: (source)

Create a join condition between two tables or selectables. e.g.:: join_condition(tablea, tableb) would produce an expression along the lines of:: tablea.c.id==tableb.c.tablea_id The join is determined based on the foreign key relationships between the two selectables. If there are multiple ways to join, or no way to join, an error is raised. :param a_subset: An optional expression that is a sub-component of ``a``. An attempt will be made to join to just this sub-component first before looking at the full ``a`` construct, and if found will be successful even if there are other ways to join to ``a``. This allows the "right side" of a join to be passed thereby providing a "natural join".

@overload
def reduce_columns(columns: Iterable[ColumnElement[Any]], *clauses: Optional[ClauseElement], **kw: bool) -> Sequence[ColumnElement[Any]]:
@overload
def reduce_columns(columns: _SelectIterable, *clauses: Optional[ClauseElement], **kw: bool) -> Sequence[Union[ColumnElement[Any], TextClause]]:
(source)

given a list of columns, return a 'reduced' set based on natural equivalents. the set is reduced to the smallest list of columns which have no natural equivalent present in the list. A "natural equivalent" means that two columns will ultimately represent the same value because they are related by a foreign key. \*clauses is an optional list of join clauses which will be traversed to further identify columns that are "equivalent". \**kw may specify 'ignore_nonexistent_tables' to ignore foreign keys whose tables are not yet configured, or columns that aren't yet present. This function is primarily used to determine the most minimal "primary key" from a selectable, by reducing the set of primary key columns present in the selectable to just those that are not repeated.

def selectables_overlap(left: FromClause, right: FromClause) -> bool: (source)

Return True if left/right have some overlapping selectable

def splice_joins(left: Optional[FromClause], right: Optional[FromClause], stop_on: Optional[FromClause] = None) -> Optional[FromClause]: (source)

Undocumented

def surface_selectables(clause): (source)

Undocumented

def surface_selectables_only(clause): (source)

Undocumented

def tables_from_leftmost(clause: FromClause) -> Iterator[FromClause]: (source)

Undocumented

def unwrap_label_reference(element): (source)

Undocumented

def unwrap_order_by(clause): (source)

Break up an 'order by' expression into individual column-expressions, without DESC/ASC/NULLS FIRST/NULLS LAST

Produce a traversal of the given expression, delivering column comparisons to the given function. The function is of the form:: def my_fn(binary, left, right) For each binary expression located which has a comparison operator, the product of "left" and "right" will be delivered to that function, in terms of that binary. Hence an expression like:: and_( (a + b) == q + func.sum(e + f), j == r ) would have the traversal:: a <eq> q a <eq> e a <eq> f b <eq> q b <eq> e b <eq> f j <eq> r That is, every combination of "left" and "right" that doesn't further contain a binary comparison is passed as pairs.

def _make_slice(limit_clause: _LimitOffsetType, offset_clause: _LimitOffsetType, start: int, stop: int) -> Tuple[Optional[ColumnElement[int]], Optional[ColumnElement[int]]]: (source)

Compute LIMIT/OFFSET in terms of slice start/end

def _offset_or_limit_clause(element: _LimitOffsetType, name: Optional[str] = None, type_: Optional[_TypeEngineArgument[int]] = None) -> ColumnElement[int]: (source)

Convert the given value to an "offset or limit" clause. This handles incoming integers and converts to an expression; if an expression is already given, it is passed through.

def _offset_or_limit_clause_asint_if_possible(clause: _LimitOffsetType) -> _LimitOffsetType: (source)

Return the offset or limit clause as a simple integer if possible, else return the clause.

def _quote_ddl_expr(element): (source)

Undocumented

def _repr_single_value(value): (source)

Undocumented

Undocumented

Value
TypeVar('_CE',
        bound='ColumnElement[Any]')