module documentation

High level utilities which build upon other modules here.
Variable join​_condition 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.
Class ​Clause​Adapter Clones and modifies clauses based on column correspondence.
Class ​Column​Adapter Extends ClauseAdapter with extra utility functions.
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 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 No summary
Function extract​_first​_column​_annotation Undocumented
Function find​_join​_source No summary
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 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.
join_condition =

Undocumented

def _make_slice(limit_clause, offset_clause, start, stop):
Compute LIMIT/OFFSET in terms of slice start/end
def _offset_or_limit_clause(element, name=None, type_=None):

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):
Return the offset or limit clause as a simple integer if possible, else return the clause.
def _quote_ddl_expr(element):

Undocumented

def adapt_criterion_to_null(crit, nulls):
given criterion containing bind params, convert selected elements to IS NULL.
def bind_values(clause):

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):

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):
traverse an expression and locate binary criterion pairs.
def expand_column_list_from_order_by(collist, 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.
def extract_first_column_annotation(column, annotation_name):

Undocumented

def find_join_source(clauses, join_to):

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, join_from):
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, join_to, onclause):

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, check_columns=False, include_aliases=False, include_joins=False, include_selects=False, include_crud=False):
locate Table objects within the given expression.
def reduce_columns(columns, *clauses, **kw):

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, right):
Return True if left/right have some overlapping selectable
def splice_joins(left, right, stop_on=None):

Undocumented

def surface_selectables(clause):

Undocumented

def surface_selectables_only(clause):

Undocumented

def tables_from_leftmost(clause):

Undocumented

def unwrap_label_reference(element):

Undocumented

def unwrap_order_by(clause):
Break up an 'order by' expression into individual column-expressions, without DESC/ASC/NULLS FIRST/NULLS LAST
def visit_binary_product(fn, expr):

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.