'except_', 'except_all', 'exists', 'extract', 'func', 'modifier',
'collate', 'insert', 'intersect', 'intersect_all', 'join', 'label',
'literal', 'literal_column', 'not_', 'null', 'nullsfirst', 'nullslast',
- 'or_', 'outparam', 'outerjoin', 'over', 'select', 'subquery', 'table', 'text',
+ 'or_', 'outparam', 'outerjoin', 'over', 'select', 'subquery',
+ 'table', 'text',
'tuple_', 'type_coerce', 'union', 'union_all', 'update', ]
PARSE_AUTOCOMMIT = util.symbol('PARSE_AUTOCOMMIT')
ORDER BY mycol DESC NULLS FIRST
"""
- return _UnaryExpression(column, modifier=operators.nullsfirst_op)
+ return UnaryExpression(column, modifier=operators.nullsfirst_op)
def nullslast(column):
"""Return a NULLS LAST ``ORDER BY`` clause element.
ORDER BY mycol DESC NULLS LAST
"""
- return _UnaryExpression(column, modifier=operators.nullslast_op)
+ return UnaryExpression(column, modifier=operators.nullslast_op)
def desc(column):
"""Return a descending ``ORDER BY`` clause element.
ORDER BY mycol DESC
"""
- return _UnaryExpression(column, modifier=operators.desc_op)
+ return UnaryExpression(column, modifier=operators.desc_op)
def asc(column):
"""Return an ascending ``ORDER BY`` clause element.
ORDER BY mycol ASC
"""
- return _UnaryExpression(column, modifier=operators.asc_op)
+ return UnaryExpression(column, modifier=operators.asc_op)
def outerjoin(left, right, onclause=None):
"""Return an ``OUTER JOIN`` clause element.
See also:
- :ref:`coretutorial_selecting` - Core Tutorial description of :func:`.select`.
+ :ref:`coretutorial_selecting` - Core Tutorial description
+ of :func:`.select`.
:param columns:
A list of :class:`.ClauseElement` objects, typically
collection of the resulting :class:`.Select` object will use these
names as well for targeting column members.
- use_labels is also available via the :meth:`~._SelectBase.apply_labels`
+ use_labels is also available via the :meth:`~.SelectBase.apply_labels`
generative method.
"""
"""Represent an ``INSERT`` statement via the :class:`.Insert` SQL
construct.
- Similar functionality is available via the :meth:`~.TableClause.insert` method on
+ Similar functionality is available via the
+ :meth:`~.TableClause.insert` method on
:class:`~.schema.Table`.
stmt = update(users).where(users.c.id==5).\\
values(name='user #5')
- Similar functionality is available via the :meth:`~.TableClause.update` method on
+ Similar functionality is available via the
+ :meth:`~.TableClause.update` method on
:class:`.Table`::
inline=inline,
**kwargs)
-def delete(table, whereclause = None, **kwargs):
+def delete(table, whereclause=None, **kwargs):
"""Represent a ``DELETE`` statement via the :class:`.Delete` SQL
construct.
- Similar functionality is available via the :meth:`~.TableClause.delete` method on
+ Similar functionality is available via the
+ :meth:`~.TableClause.delete` method on
:class:`~.schema.Table`.
:param table: The table to be updated.
"""Join a list of clauses together using the ``AND`` operator.
The ``&`` operator is also overloaded on all
- :class:`_CompareMixin` subclasses to produce the
+ :class:`CompareMixin` subclasses to produce the
same result.
"""
"""Join a list of clauses together using the ``OR`` operator.
The ``|`` operator is also overloaded on all
- :class:`_CompareMixin` subclasses to produce the
+ :class:`CompareMixin` subclasses to produce the
same result.
"""
"""Return a negation of the given clause, i.e. ``NOT(clause)``.
The ``~`` operator is also overloaded on all
- :class:`_CompareMixin` subclasses to produce the
+ :class:`CompareMixin` subclasses to produce the
same result.
"""
"""
expr = _literal_as_binds(expr)
- return _UnaryExpression(expr, operator=operators.distinct_op, type_=expr.type)
+ return UnaryExpression(expr,
+ operator=operators.distinct_op, type_=expr.type)
def between(ctest, cleft, cright):
"""Return a ``BETWEEN`` predicate clause.
Equivalent of SQL ``clausetest BETWEEN clauseleft AND clauseright``.
The :func:`between()` method on all
- :class:`_CompareMixin` subclasses provides
+ :class:`CompareMixin` subclasses provides
similar functionality.
"""
"""
- return _Case(whens, value=value, else_=else_)
+ return Case(whens, value=value, else_=else_)
def cast(clause, totype, **kwargs):
"""Return a ``CAST`` function.
cast(table.c.timestamp, DATE)
"""
- return _Cast(clause, totype, **kwargs)
+ return Cast(clause, totype, **kwargs)
def extract(field, expr):
"""Return the clause ``extract(field FROM expr)``."""
- return _Extract(field, expr)
+ return Extract(field, expr)
def collate(expression, collation):
"""Return the clause ``expression COLLATE collation``.
"""
expr = _literal_as_binds(expression)
- return _BinaryExpression(
+ return BinaryExpression(
expr,
_literal_as_text(collation),
operators.collate, type_=expr.type)
exists().where(table.c.col2==5)
"""
- return _Exists(*args, **kwargs)
+ return Exists(*args, **kwargs)
def union(*selects, **kwargs):
"""Return a ``UNION`` of multiple selectables.
Literal clauses are created automatically when non- :class:`.ClauseElement`
objects (such as strings, ints, dates, etc.) are used in a comparison
- operation with a :class:`_CompareMixin`
- subclass, such as a :class:`~sqlalchemy.schema.Column` object. Use this function to force the
+ operation with a :class:`CompareMixin`
+ subclass, such as a :class:`~sqlalchemy.schema.Column` object.
+ Use this function to force the
generation of a literal clause, which will be created as a
- :class:`_BindParamClause` with a bound value.
+ :class:`BindParameter` with a bound value.
:param value: the value to be bound. Can be any Python object supported by
the underlying DB-API, or is translatable via the given type argument.
will provide bind-parameter translation for this literal.
"""
- return _BindParamClause(None, value, type_=type_, unique=True)
+ return BindParameter(None, value, type_=type_, unique=True)
def tuple_(*expr):
"""Return a SQL tuple.
an expression is invoked.
"""
- return _Tuple(*expr)
+ return Tuple(*expr)
def type_coerce(expr, type_):
- """Coerce the given expression into the given type, on the Python side only.
+ """Coerce the given expression into the given type,
+ on the Python side only.
:func:`.type_coerce` is roughly similar to :func:`.cast`, except no
"CAST" expression is rendered - the given type is only applied towards
else:
return literal(expr, type_=type_)
else:
- return _Label(None, expr, type_=type_)
+ return Label(None, expr, type_=type_)
def label(name, obj):
- """Return a :class:`_Label` object for the
+ """Return a :class:`Label` object for the
given :class:`.ColumnElement`.
A label changes the name of an element in the columns clause of a
a :class:`.ColumnElement`.
"""
- return _Label(name, obj)
+ return Label(name, obj)
def column(text, type_=None):
"""Return a textual column clause, as would be in the columns clause of a
The object returned is an instance of :class:`.ColumnClause`, which
represents the "syntactical" portion of the schema-level
:class:`~sqlalchemy.schema.Column` object. It is often used directly
- within :func:`~.expression.select` constructs or with lightweight :func:`~.expression.table`
- constructs.
+ within :func:`~.expression.select` constructs or with lightweight
+ :func:`~.expression.table` constructs.
Note that the :func:`~.expression.column` function is not part of
- the ``sqlalchemy`` namespace. It must be imported from the ``sql`` package::
+ the ``sqlalchemy`` namespace. It must be imported from the
+ ``sql`` package::
from sqlalchemy.sql import table, column
which should be subject to quoting rules, use the :func:`column`
function.
- :param type\_: an optional :class:`~sqlalchemy.types.TypeEngine` object which will
+ :param type\_: an optional :class:`~sqlalchemy.types.TypeEngine`
+ object which will
provide result-set translation and additional expression semantics for
this column. If left as None the type will be NullType.
the key for this bind param. Will be used in the generated
SQL statement for dialects that use named parameters. This
value may be modified when part of a compilation operation,
- if other :class:`_BindParamClause` objects exist with the same
+ if other :class:`BindParameter` objects exist with the same
key, or if its length is too long and truncation is
required.
:param type\_:
A ``TypeEngine`` object that will be used to pre-process the
- value corresponding to this :class:`_BindParamClause` at
+ value corresponding to this :class:`BindParameter` at
execution time.
:param unique:
if True, the key name of this BindParamClause will be
- modified if another :class:`_BindParamClause` of the same name
+ modified if another :class:`BindParameter` of the same name
already has been located within the containing
:class:`.ClauseElement`.
if isinstance(key, ColumnClause):
type_ = key.type
key = key.name
- return _BindParamClause(key, value, type_=type_,
+ return BindParameter(key, value, type_=type_,
callable_=callable_,
unique=unique, required=required,
quote=quote)
attribute, which returns a dictionary containing the values.
"""
- return _BindParamClause(
+ return BindParameter(
key, None, type_=type_, unique=False, isoutparam=True)
def text(text, bind=None, *args, **kwargs):
that returns result sets.
"""
- return _TextClause(text, bind=bind, *args, **kwargs)
+ return TextClause(text, bind=bind, *args, **kwargs)
def over(func, partition_by=None, order_by=None):
"""Produce an OVER clause against a function.
.. versionadded:: 0.7
"""
- return _Over(func, partition_by=partition_by, order_by=order_by)
+ return Over(func, partition_by=partition_by, order_by=order_by)
def null():
- """Return a :class:`_Null` object, which compiles to ``NULL``.
+ """Return a :class:`Null` object, which compiles to ``NULL``.
"""
- return _Null()
+ return Null()
def true():
- """Return a :class:`_True` object, which compiles to ``true``, or the
+ """Return a :class:`True_` object, which compiles to ``true``, or the
boolean equivalent for the target dialect.
"""
- return _True()
+ return True_()
def false():
- """Return a :class:`_False` object, which compiles to ``false``, or the
+ """Return a :class:`False_` object, which compiles to ``false``, or the
boolean equivalent for the target dialect.
"""
- return _False()
+ return False_()
class _FunctionGenerator(object):
"""Generate :class:`.Function` objects based on getattr calls."""
func = _FunctionGenerator()
"""Generate SQL function expressions.
- ``func`` is a special object instance which generates SQL functions based on name-based attributes, e.g.::
+ ``func`` is a special object instance which generates SQL
+ functions based on name-based attributes, e.g.::
>>> print func.count(1)
count(:param_1)
>>> print func.current_timestamp()
CURRENT_TIMESTAMP
- To call functions which are present in dot-separated packages, specify them in the same manner::
+ To call functions which are present in dot-separated packages,
+ specify them in the same manner::
>>> print func.stats.yield_curve(5, 10)
stats.yield_curve(:yield_curve_1, :yield_curve_2)
elif hasattr(element, '__clause_element__'):
return element.__clause_element__()
elif isinstance(element, basestring):
- return _TextClause(unicode(element))
+ return TextClause(unicode(element))
elif isinstance(element, (util.NoneType, bool)):
return _const_expr(element)
else:
if element is None:
return null()
else:
- return _BindParamClause(name, element, type_=type_, unique=True)
+ return BindParameter(name, element, type_=type_, unique=True)
else:
return element
"failed to locate a corresponding column from table '%s'"
%
(column,
- getattr(column, 'table', None),fromclause.description)
+ getattr(column, 'table', None),
+ fromclause.description)
)
return c
bind.value = kwargs[bind.key]
if unique:
bind._convert_to_unique()
- return cloned_traverse(self, {}, {'bindparam':visit_bindparam})
+ return cloned_traverse(self, {}, {'bindparam': visit_bindparam})
def compare(self, other, **kw):
"""Compare this ClauseElement to the given ClauseElement.
if hasattr(self, 'negation_clause'):
return self.negation_clause
else:
- return _UnaryExpression(
+ return UnaryExpression(
self.self_group(against=operators.inv),
operator=operators.inv,
negate=None)
inspection._self_inspects(ClauseElement)
-class _Immutable(object):
+class Immutable(object):
"""mark a ClauseElement as 'immutable' when expressions are cloned."""
def unique_params(self, *optionaldict, **kwargs):
return self
-class _CompareMixin(ColumnOperators):
+class CompareMixin(ColumnOperators):
"""Defines comparison and math operations for :class:`.ClauseElement`
instances.
def __compare(self, op, obj, negate=None, reverse=False,
**kwargs
):
- if obj is None or isinstance(obj, _Null):
+ if obj is None or isinstance(obj, Null):
if op == operators.eq:
- return _BinaryExpression(self, null(), operators.is_,
+ return BinaryExpression(self, null(), operators.is_,
negate=operators.isnot)
elif op == operators.ne:
- return _BinaryExpression(self, null(), operators.isnot,
+ return BinaryExpression(self, null(), operators.isnot,
negate=operators.is_)
else:
raise exc.ArgumentError("Only '='/'!=' operators can "
obj = self._check_literal(op, obj)
if reverse:
- return _BinaryExpression(obj,
+ return BinaryExpression(obj,
self,
op,
type_=sqltypes.BOOLEANTYPE,
negate=negate, modifiers=kwargs)
else:
- return _BinaryExpression(self,
+ return BinaryExpression(self,
obj,
op,
type_=sqltypes.BOOLEANTYPE,
else:
op, result_type = left.type._adapt_expression(op,
right.type)
- return _BinaryExpression(left, right, op, type_=result_type)
+ return BinaryExpression(left, right, op, type_=result_type)
# a mapping of operators with the method they use, along with their negated
}
def operate(self, op, *other, **kwargs):
- o = _CompareMixin.operators[op]
+ o = CompareMixin.operators[op]
return o[0](self, op, other[0], *o[1:], **kwargs)
def reverse_operate(self, op, other, **kwargs):
- o = _CompareMixin.operators[op]
+ o = CompareMixin.operators[op]
return o[0](self, op, other, reverse=True, *o[1:], **kwargs)
def in_(self, other):
def _in_impl(self, op, negate_op, seq_or_selectable):
seq_or_selectable = _clause_element_as_expr(seq_or_selectable)
- if isinstance(seq_or_selectable, _ScalarSelect):
+ if isinstance(seq_or_selectable, ScalarSelect):
return self.__compare(op, seq_or_selectable,
negate=negate_op)
- elif isinstance(seq_or_selectable, _SelectBase):
+ elif isinstance(seq_or_selectable, SelectBase):
# TODO: if we ever want to support (x, y, z) IN (select x,
# y, z from table), we would need a multi-column version of
return self.__compare(op, seq_or_selectable.as_scalar(),
negate=negate_op)
- elif isinstance(seq_or_selectable, (Selectable, _TextClause)):
+ elif isinstance(seq_or_selectable, (Selectable, TextClause)):
return self.__compare(op, seq_or_selectable,
negate=negate_op)
args = []
for o in seq_or_selectable:
if not _is_literal(o):
- if not isinstance(o, _CompareMixin):
+ if not isinstance(o, CompareMixin):
raise exc.InvalidRequestError('in() function accept'
's either a list of non-selectable values, '
'or a selectable: %r' % o)
def __neg__(self):
"""See :meth:`.ColumnOperators.__neg__`."""
- return _UnaryExpression(self, operator=operators.neg)
+ return UnaryExpression(self, operator=operators.neg)
def startswith(self, other, escape=None):
"""See :meth:`.ColumnOperators.startswith`."""
if 'name' is None, an anonymous label name will be generated.
"""
- return _Label(name, self, self.type)
+ return Label(name, self, self.type)
def desc(self):
"""See :meth:`.ColumnOperators.desc`."""
def distinct(self):
"""See :meth:`.ColumnOperators.distinct`."""
- return _UnaryExpression(self, operator=operators.distinct_op,
+ return UnaryExpression(self, operator=operators.distinct_op,
type_=self.type)
def between(self, cleft, cright):
"""See :meth:`.ColumnOperators.between`."""
- return _BinaryExpression(
+ return BinaryExpression(
self,
ClauseList(
self._check_literal(operators.and_, cleft),
return lambda other: self.__operate(operator, other)
def _bind_param(self, operator, obj):
- return _BindParamClause(None, obj,
+ return BindParameter(None, obj,
_compared_to_operator=operator,
_compared_to_type=self.type, unique=True)
def _check_literal(self, operator, other):
- if isinstance(other, _BindParamClause) and \
+ if isinstance(other, BindParameter) and \
isinstance(other.type, sqltypes.NullType):
# TODO: perhaps we should not mutate the incoming bindparam()
# here and instead make a copy of it. this might
return other
elif hasattr(other, '__clause_element__'):
other = other.__clause_element__()
- if isinstance(other, (_SelectBase, Alias)):
+ if isinstance(other, (SelectBase, Alias)):
other = other.as_scalar()
return other
elif not isinstance(other, ClauseElement):
return self._bind_param(operator, other)
- elif isinstance(other, (_SelectBase, Alias)):
+ elif isinstance(other, (SelectBase, Alias)):
return other.as_scalar()
else:
return other
-class ColumnElement(ClauseElement, _CompareMixin):
+class ColumnElement(ClauseElement, CompareMixin):
"""Represent an element that is usable within the "column clause" portion
of a ``SELECT`` statement.
An example of a "derived" :class:`.Selectable` is an :class:`.Alias` of a
:class:`~sqlalchemy.schema.Table`.
- A :class:`.ColumnElement`, by subclassing the :class:`_CompareMixin` mixin
+ A :class:`.ColumnElement`, by subclassing the :class:`CompareMixin` mixin
class, provides the ability to generate new :class:`.ClauseElement`
- objects using Python expressions. See the :class:`_CompareMixin`
+ objects using Python expressions. See the :class:`CompareMixin`
docstring for more details.
"""
for c in other:
for local in self:
if c.shares_lineage(local):
- l.append(c==local)
+ l.append(c == local)
return and_(*l)
def __contains__(self, other):
for c in other:
for local in self:
if c.shares_lineage(local):
- l.append(c==local)
+ l.append(c == local)
return and_(*l)
def __hash__(self):
def _populate_column_collection(self):
pass
-class _BindParamClause(ColumnElement):
+class BindParameter(ColumnElement):
"""Represent a bind parameter.
Public constructor is the :func:`bindparam()` function.
quote=None,
_compared_to_operator=None,
_compared_to_type=None):
- """Construct a _BindParamClause.
+ """Construct a BindParameter.
:param key:
the key for this bind param. Will be used in the generated
SQL statement for dialects that use named parameters. This
value may be modified when part of a compilation operation,
- if other :class:`_BindParamClause` objects exist with the same
+ if other :class:`BindParameter` objects exist with the same
key, or if its length is too long and truncation is
required.
:param type\_:
A ``TypeEngine`` object that will be used to pre-process the
- value corresponding to this :class:`_BindParamClause` at
+ value corresponding to this :class:`BindParameter` at
execution time.
:param unique:
if True, the key name of this BindParamClause will be
- modified if another :class:`_BindParamClause` of the same name
+ modified if another :class:`BindParameter` of the same name
already has been located within the containing
:class:`.ClauseElement`.
self._orig_key or 'param'))
def compare(self, other, **kw):
- """Compare this :class:`_BindParamClause` to the given
+ """Compare this :class:`BindParameter` to the given
clause."""
- return isinstance(other, _BindParamClause) \
+ return isinstance(other, BindParameter) \
and self.type._compare_type_affinity(other.type) \
and self.value == other.value
return d
def __repr__(self):
- return '_BindParamClause(%r, %r, type_=%r)' % (self.key,
+ return 'BindParameter(%r, %r, type_=%r)' % (self.key,
self.value, self.type)
-class _TypeClause(ClauseElement):
+class TypeClause(ClauseElement):
"""Handle a type keyword in a SQL statement.
Used by the ``Case`` statement.
self.type = type
-class _Generative(object):
+class Generative(object):
"""Allow a ClauseElement to generate itself via the
@_generative decorator.
return s
-class Executable(_Generative):
+class Executable(Generative):
"""Mark a ClauseElement as supporting execution.
:class:`.Executable` is a superclass for all "statement" types
# legacy, some outside users may be calling this
_Executable = Executable
-class _TextClause(Executable, ClauseElement):
+class TextClause(Executable, ClauseElement):
"""Represent a literal SQL text fragment.
Public constructor is the :func:`text()` function.
_bind_params_regex = re.compile(r'(?<![:\w\x5c]):(\w+)(?!:)', re.UNICODE)
_execution_options = \
- Executable._execution_options.union({'autocommit'
- : PARSE_AUTOCOMMIT})
+ Executable._execution_options.union(
+ {'autocommit': PARSE_AUTOCOMMIT})
@property
def _select_iterable(self):
'Use .execution_options(autocommit=Tru'
'e)')
self._execution_options = \
- self._execution_options.union({'autocommit'
- : autocommit})
+ self._execution_options.union(
+ {'autocommit': autocommit})
if typemap is not None:
for key in typemap.keys():
typemap[key] = sqltypes.to_instance(typemap[key])
def self_group(self, against=None):
if against is operators.in_op:
- return _Grouping(self)
+ return Grouping(self)
else:
return self
return self.bindparams.values()
-class _Null(ColumnElement):
+class Null(ColumnElement):
"""Represent the NULL keyword in a SQL statement.
Public constructor is the :func:`null()` function.
"""
__visit_name__ = 'null'
+
def __init__(self):
self.type = sqltypes.NULLTYPE
-class _False(ColumnElement):
+class False_(ColumnElement):
"""Represent the ``false`` keyword in a SQL statement.
Public constructor is the :func:`false()` function.
"""
__visit_name__ = 'false'
+
def __init__(self):
self.type = sqltypes.BOOLEANTYPE
-class _True(ColumnElement):
+class True_(ColumnElement):
"""Represent the ``true`` keyword in a SQL statement.
Public constructor is the :func:`true()` function.
"""
__visit_name__ = 'true'
+
def __init__(self):
self.type = sqltypes.BOOLEANTYPE
def self_group(self, against=None):
if self.group and operators.is_precedent(self.operator, against):
- return _Grouping(self)
+ return Grouping(self)
else:
return self
else:
return super(BooleanClauseList, self).self_group(against=against)
-class _Tuple(ClauseList, ColumnElement):
+class Tuple(ClauseList, ColumnElement):
def __init__(self, *clauses, **kw):
clauses = [_literal_as_binds(c) for c in clauses]
- super(_Tuple, self).__init__(*clauses, **kw)
+ super(Tuple, self).__init__(*clauses, **kw)
self.type = _type_from_args(clauses)
@property
return (self, )
def _bind_param(self, operator, obj):
- return _Tuple(*[
- _BindParamClause(None, o, _compared_to_operator=operator,
+ return Tuple(*[
+ BindParameter(None, o, _compared_to_operator=operator,
_compared_to_type=self.type, unique=True)
for o in obj
]).self_group()
-class _Case(ColumnElement):
+class Case(ColumnElement):
__visit_name__ = 'case'
def __init__(self, whens, value=None, else_=None):
return self.select().execute()
def _bind_param(self, operator, obj):
- return _BindParamClause(None, obj, _compared_to_operator=operator,
+ return BindParameter(None, obj, _compared_to_operator=operator,
_compared_to_type=self.type, unique=True)
FunctionElement.__init__(self, *clauses, **kw)
def _bind_param(self, operator, obj):
- return _BindParamClause(self.name, obj,
+ return BindParameter(self.name, obj,
_compared_to_operator=operator,
_compared_to_type=self.type,
unique=True)
-class _Cast(ColumnElement):
+class Cast(ColumnElement):
__visit_name__ = 'cast'
def __init__(self, clause, totype, **kwargs):
self.type = sqltypes.to_instance(totype)
self.clause = _literal_as_binds(clause, None)
- self.typeclause = _TypeClause(self.type)
+ self.typeclause = TypeClause(self.type)
def _copy_internals(self, clone=_clone, **kw):
self.clause = clone(self.clause, **kw)
return self.clause._from_objects
-class _Extract(ColumnElement):
+class Extract(ColumnElement):
__visit_name__ = 'extract'
return self.expr._from_objects
-class _UnaryExpression(ColumnElement):
+class UnaryExpression(ColumnElement):
__visit_name__ = 'unary'
return self.element,
def compare(self, other, **kw):
- """Compare this :class:`_UnaryExpression` against the given
+ """Compare this :class:`UnaryExpression` against the given
:class:`.ClauseElement`."""
return (
- isinstance(other, _UnaryExpression) and
+ isinstance(other, UnaryExpression) and
self.operator == other.operator and
self.modifier == other.modifier and
self.element.compare(other.element, **kw)
def _negate(self):
if self.negate is not None:
- return _UnaryExpression(
+ return UnaryExpression(
self.element,
operator=self.negate,
negate=self.operator,
modifier=self.modifier,
type_=self.type)
else:
- return super(_UnaryExpression, self)._negate()
+ return super(UnaryExpression, self)._negate()
def self_group(self, against=None):
if self.operator and operators.is_precedent(self.operator,
against):
- return _Grouping(self)
+ return Grouping(self)
else:
return self
-class _BinaryExpression(ColumnElement):
+class BinaryExpression(ColumnElement):
"""Represent an expression that is ``LEFT <operator> RIGHT``."""
__visit_name__ = 'binary'
return self.left, self.right
def compare(self, other, **kw):
- """Compare this :class:`_BinaryExpression` against the
- given :class:`_BinaryExpression`."""
+ """Compare this :class:`BinaryExpression` against the
+ given :class:`BinaryExpression`."""
return (
- isinstance(other, _BinaryExpression) and
+ isinstance(other, BinaryExpression) and
self.operator == other.operator and
(
self.left.compare(other.left, **kw) and
def self_group(self, against=None):
if operators.is_precedent(self.operator, against):
- return _Grouping(self)
+ return Grouping(self)
else:
return self
def _negate(self):
if self.negate is not None:
- return _BinaryExpression(
+ return BinaryExpression(
self.left,
self.right,
self.negate,
type_=sqltypes.BOOLEANTYPE,
modifiers=self.modifiers)
else:
- return super(_BinaryExpression, self)._negate()
+ return super(BinaryExpression, self)._negate()
-class _Exists(_UnaryExpression):
- __visit_name__ = _UnaryExpression.__visit_name__
+class Exists(UnaryExpression):
+ __visit_name__ = UnaryExpression.__visit_name__
_from_objects = []
def __init__(self, *args, **kwargs):
- if args and isinstance(args[0], (_SelectBase, _ScalarSelect)):
+ if args and isinstance(args[0], (SelectBase, ScalarSelect)):
s = args[0]
else:
if not args:
args = ([literal_column('*')],)
s = select(*args, **kwargs).as_scalar().self_group()
- _UnaryExpression.__init__(self, s, operator=operators.exists,
+ UnaryExpression.__init__(self, s, operator=operators.exists,
type_=sqltypes.Boolean)
def select(self, whereclause=None, **params):
return e
def select_from(self, clause):
- """return a new :class:`._Exists` construct, applying the given expression
+ """return a new :class:`.Exists` construct, applying the given expression
to the :meth:`.Select.select_from` method of the select statement
contained.
self.right.is_derived_from(fromclause)
def self_group(self, against=None):
- return _FromGrouping(self)
+ return FromGrouping(self)
def _populate_column_collection(self):
columns = [c for c in self.left.columns] + \
"""Represent a Common Table Expression.
The :class:`.CTE` object is obtained using the
- :meth:`._SelectBase.cte` method from any selectable.
+ :meth:`.SelectBase.cte` method from any selectable.
See that method for complete examples.
.. versionadded:: 0.7.6
)
-class _Grouping(ColumnElement):
+class Grouping(ColumnElement):
"""Represent a grouping within a column expression"""
__visit_name__ = 'grouping'
self.element = state['element']
self.type = state['type']
-class _FromGrouping(FromClause):
+class FromGrouping(FromClause):
"""Represent a grouping of a FROM clause"""
__visit_name__ = 'grouping'
return getattr(self.element, attr)
def __getstate__(self):
- return {'element':self.element}
+ return {'element': self.element}
def __setstate__(self, state):
self.element = state['element']
-class _Over(ColumnElement):
+class Over(ColumnElement):
"""Represent an OVER clause.
This is a special operator against a so-called
if c is not None]
))
-class _Label(ColumnElement):
+class Label(ColumnElement):
"""Represents a column label (AS).
Represent a label, as typically applied to any column-level
__visit_name__ = 'label'
def __init__(self, name, element, type_=None):
- while isinstance(element, _Label):
+ while isinstance(element, Label):
element = element.element
if name:
self.name = name
def self_group(self, against=None):
sub_element = self._element.self_group(against=against)
if sub_element is not self._element:
- return _Label(self.name,
+ return Label(self.name,
sub_element,
type_=self._type)
else:
e.proxies.append(self)
return e
-class ColumnClause(_Immutable, ColumnElement):
+class ColumnClause(Immutable, ColumnElement):
"""Represents a generic column expression from any textual string.
This includes columns associated with tables, aliases and select
def _get_table(self):
return self.__dict__['table']
+
def _set_table(self, table):
self._memoized_property.expire_instance(self)
self.__dict__['table'] = table
def _bind_param(self, operator, obj):
- return _BindParamClause(self.name, obj,
+ return BindParameter(self.name, obj,
_compared_to_operator=operator,
_compared_to_type=self.type,
unique=True)
selectable._columns[c.key] = c
return c
-class TableClause(_Immutable, FromClause):
+class TableClause(Immutable, FromClause):
"""Represents a minimal "table" construct.
The constructor for :class:`.TableClause` is the
of :class:`~.schema.Table`, including constraints, references to other
tables, or support for :class:`.MetaData`-level services. It's useful
on its own as an ad-hoc construct used to generate quick SQL
- statements when a more fully fledged :class:`~.schema.Table` is not on hand.
+ statements when a more fully fledged :class:`~.schema.Table`
+ is not on hand.
"""
def _from_objects(self):
return [self]
-class _SelectBase(Executable, FromClause):
+class SelectBase(Executable, FromClause):
"""Base class for :class:`.Select` and ``CompoundSelects``."""
_order_by_clause = ClauseList()
'deprecated. Use .execution_options(a'
'utocommit=True)')
self._execution_options = \
- self._execution_options.union({'autocommit'
- : autocommit})
+ self._execution_options.union(
+ {'autocommit': autocommit})
if limit is not None:
self._limit = util.asint(limit)
if offset is not None:
clause is eligible to be used as a scalar expression.
The returned object is an instance of
- :class:`_ScalarSelect`.
+ :class:`ScalarSelect`.
"""
- return _ScalarSelect(self)
+ return ScalarSelect(self)
@_generative
def apply_labels(self):
"""return a 'scalar' representation of this selectable, embedded as a
subquery with a label.
- See also :meth:`~._SelectBase.as_scalar`.
+ See also :meth:`~.SelectBase.as_scalar`.
"""
return self.as_scalar().label(name)
statement = select([
included_parts.c.sub_part,
- func.sum(included_parts.c.quantity).label('total_quantity')
+ func.sum(included_parts.c.quantity).
+ label('total_quantity')
]).\
select_from(included_parts.join(parts,
included_parts.c.part==parts.c.part)).\\
See also:
- :meth:`.orm.query.Query.cte` - ORM version of :meth:`._SelectBase.cte`.
+ :meth:`.orm.query.Query.cte` - ORM version of :meth:`.SelectBase.cte`.
"""
return CTE(self, name=name, recursive=recursive)
return [self]
-class _ScalarSelect(_Grouping):
+class ScalarSelect(Grouping):
_from_objects = []
def __init__(self, element):
return list(self.inner_columns)[0]._make_proxy(
selectable, name=name)
-class CompoundSelect(_SelectBase):
+class CompoundSelect(SelectBase):
"""Forms the basis of ``UNION``, ``UNION ALL``, and other
SELECT-based set operations."""
self.selects.append(s.self_group(self))
- _SelectBase.__init__(self, **kwargs)
+ SelectBase.__init__(self, **kwargs)
def _scalar_type(self):
return self.selects[0]._scalar_type()
def self_group(self, against=None):
- return _FromGrouping(self)
+ return FromGrouping(self)
def is_derived_from(self, fromclause):
for s in self.selects:
return e
else:
return None
+
def _set_bind(self, bind):
self._bind = bind
bind = property(bind, _set_bind)
-class Select(_SelectBase):
+class Select(SelectBase):
"""Represents a ``SELECT`` statement.
See also:
- :func:`~.expression.select` - the function which creates a :class:`.Select` object.
+ :func:`~.expression.select` - the function which creates
+ a :class:`.Select` object.
- :ref:`coretutorial_selecting` - Core Tutorial description of :func:`.select`.
+ :ref:`coretutorial_selecting` - Core Tutorial description
+ of :func:`.select`.
"""
_from_cloned = None
_correlate = ()
_correlate_except = ()
- _memoized_property = _SelectBase._memoized_property
+ _memoized_property = SelectBase._memoized_property
def __init__(self,
columns,
argument descriptions.
Additional generative and mutator methods are available on the
- :class:`_SelectBase` superclass.
+ :class:`SelectBase` superclass.
"""
self._should_correlate = correlate
self._raw_columns = []
for c in columns:
c = _literal_as_column(c)
- if isinstance(c, _ScalarSelect):
+ if isinstance(c, ScalarSelect):
c = c.self_group(against=operators.comma_op)
self._raw_columns.append(c)
else:
if prefixes:
self._prefixes = tuple([_literal_as_text(p) for p in prefixes])
- _SelectBase.__init__(self, **kwargs)
+ SelectBase.__init__(self, **kwargs)
@property
def _froms(self):
froms = []
seen = set()
translate = self._from_cloned
+
def add(items):
for item in items:
if translate and item in translate:
if len(froms) > 1 or self._correlate or self._correlate_except:
if self._correlate:
- froms = [f for f in froms if f not in _cloned_intersection(froms,
+ froms = [f for f in froms if f not in
+ _cloned_intersection(froms,
self._correlate)]
if self._correlate_except:
froms = [f for f in froms if f in _cloned_intersection(froms,
self._correlate_except)]
if self._should_correlate and existing_froms:
- froms = [f for f in froms if f not in _cloned_intersection(froms,
+ froms = [f for f in froms if f not in
+ _cloned_intersection(froms,
existing_froms)]
if not len(froms):
with_hint(mytable, "WITH INDEX ix_mytable", 'sybase')
"""
- self._hints = self._hints.union({(selectable, dialect_name):text})
+ self._hints = self._hints.union(
+ {(selectable, dialect_name): text})
@property
def type(self):
:meth:`.Select.select_from`::
>>> s1 = select([table1.c.a, table2.c.b]).\\
- ... select_from(table1.join(table2, table1.c.a==table2.c.a))
+ ... select_from(table1.join(table2,
+ ... table1.c.a==table2.c.a))
>>> s2 = s1.with_only_columns([table2.c.b])
>>> print s2
SELECT t2.b FROM t1 JOIN t2 ON t1.a=t2.a
rc = []
for c in columns:
c = _literal_as_column(c)
- if isinstance(c, _ScalarSelect):
+ if isinstance(c, ScalarSelect):
c = c.self_group(against=operators.comma_op)
rc.append(c)
self._raw_columns = rc
@_generative
def select_from(self, fromclause):
- """return a new :func:`.select` construct with the given FROM expression
+ """return a new :func:`.select` construct with the
+ given FROM expression
merged into its list of FROM objects.
E.g.::
will have no effect. Passing a :class:`.Join` that refers
to an already present :class:`.Table` or other selectable will have
the effect of concealing the presence of that selectable as
- an individual element in the rendered FROM list, instead rendering it into a
- JOIN clause.
+ an individual element in the rendered FROM list, instead
+ rendering it into a JOIN clause.
- While the typical purpose of :meth:`.Select.select_from` is to replace
- the default, derived FROM clause with a join, it can also be called with
- individual table elements, multiple times if desired, in the case that the
- FROM clause cannot be fully derived from the columns clause::
+ While the typical purpose of :meth:`.Select.select_from` is to
+ replace the default, derived FROM clause with a join, it can
+ also be called with individual table elements, multiple times
+ if desired, in the case that the FROM clause cannot be fully
+ derived from the columns clause::
select([func.count('*')]).select_from(table1)
if fromclauses and fromclauses[0] is None:
self._correlate_except = ()
else:
- self._correlate_except = set(self._correlate_except).union(fromclauses)
+ self._correlate_except = set(self._correlate_except
+ ).union(fromclauses)
def append_correlation(self, fromclause):
"""append the given correlation expression to this select()
self._reset_exported()
column = _literal_as_column(column)
- if isinstance(column, _ScalarSelect):
+ if isinstance(column, ScalarSelect):
column = column.self_group(against=operators.comma_op)
self._raw_columns = self._raw_columns + [column]
"""
if isinstance(against, CompoundSelect):
return self
- return _FromGrouping(self)
+ return FromGrouping(self)
def union(self, other, **kwargs):
"""return a SQL UNION of this select() construct against the given
bind = property(bind, _set_bind)
_returning_re = re.compile(r'(?:firebird|postgres(?:ql)?)_returning')
+
def _process_deprecated_kw(self, kwargs):
for k in list(kwargs):
m = self._returning_re.match(k)
if selectable is None:
selectable = self.table
- self._hints = self._hints.union({(selectable, dialect_name):text})
+ self._hints = self._hints.union(
+ {(selectable, dialect_name): text})
class ValuesBase(UpdateBase):
- """Supplies support for :meth:`.ValuesBase.values` to INSERT and UPDATE constructs."""
+ """Supplies support for :meth:`.ValuesBase.values` to
+ INSERT and UPDATE constructs."""
__visit_name__ = 'values_base'
users.insert().values({users.c.name : "some name"})
- users.update().where(users.c.id==5).values({users.c.name : "some name"})
+ users.update().where(users.c.id==5).values(
+ {users.c.name: "some name"})
See also:
class Insert(ValuesBase):
"""Represent an INSERT construct.
- The :class:`.Insert` object is created using the :func:`~.expression.insert()` function.
+ The :class:`.Insert` object is created using the
+ :func:`~.expression.insert()` function.
See also:
table,
whereclause,
bind=None,
- returning =None,
+ returning=None,
**kwargs):
self._bind = bind
self.table = table
class ReleaseSavepointClause(_IdentifiedClause):
__visit_name__ = 'release_savepoint'
+# old names for compatibility
+_BindParamClause = BindParameter
+_Label = Label
+_CompareMixin = CompareMixin
+_SelectBase = SelectBase
+_BinaryExpression = BinaryExpression
+_Cast = Cast
+_Null = Null
+_False = False_
+_True = True_
+_TextClause = TextClause
+_UnaryExpression = UnaryExpression
+_Case = Case
+_Tuple = Tuple
+_Over = Over
+_Generative = Generative
+_TypeClause = TypeClause
+_Extract = Extract
+_Exists = Exists
+_Grouping = Grouping
+_FromGrouping = FromGrouping
+_ScalarSelect = ScalarSelect