summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-08-18 10:41:17 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-08-18 10:41:17 -0400
commitb47c185fc4b09f0ee8f8445fb1b7ea41beafa0d7 (patch)
treee2bec32edcfa41b2304c2a0c1bd6e6940ae0b626 /lib/sqlalchemy
parent24a071921c2e8133a393284c700c106e13242cf5 (diff)
downloadsqlalchemy-b47c185fc4b09f0ee8f8445fb1b7ea41beafa0d7.tar.gz
tighten this up
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/sql/expression.py16
-rw-r--r--lib/sqlalchemy/types.py51
2 files changed, 9 insertions, 58 deletions
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index 969a6920b..0974b7e50 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -2141,21 +2141,21 @@ class _DefaultColumnComparator(operators.ColumnOperators):
class ColumnElement(ClauseElement, ColumnOperators):
- """Represent an element that is usable within the "column clause" portion
- of a ``SELECT`` statement.
+ """Represent a column-oriented SQL expression suitable for usage in the
+ "columns" clause, WHERE clause etc. of a statement.
While the most familiar kind of :class:`.ColumnElement` is the
:class:`.Column` object, :class:`.ColumnElement` serves as the basis
for any unit that may be present in a SQL expression, including
- the columns associated with tables, aliases, and
- subqueries, expressions, function calls, SQL keywords such as
- ``NULL``, literals, etc. :class:`.ColumnElement` is the ultimate base
- class for all such elements.
+ the expressions themselves, SQL functions, bound parameters,
+ literal expressions, keywords such as ``NULL``, etc. :class:`.ColumnElement`
+ is the ultimate base class for all such elements.
- A :class:`.ColumnElement` provides the ability to generate new :class:`.ClauseElement`
+ A :class:`.ColumnElement` provides the ability to generate new
+ :class:`.ColumnElement`
objects using Python expressions. This means that Python operators
such as ``==``, ``!=`` and ``<`` are overloaded to mimic SQL operations,
- and allow the construction of :class:`.ColumnElement` constructs which
+ and allow the instantiation of further :class:`.ColumnElement` instances which
are composed from other, more fundamental :class:`.ColumnElement`
objects. For example, two :class:`.ColumnClause` objects can be added
together with the addition operator ``+`` to produce
diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py
index 6c936fa3e..a082daf63 100644
--- a/lib/sqlalchemy/types.py
+++ b/lib/sqlalchemy/types.py
@@ -74,56 +74,7 @@ class TypeEngine(AbstractType):
Rudimentary usage of this hook is allowed through simple subclassing
of existing types, or alternatively by using :class:`.TypeDecorator`.
- E.g. to overload the ``+`` operator on :class:`.Integer`::
-
- from sqlalchemy import Integer
-
- class MyInt(Integer):
- class comparator_factory(Integer.Comparator):
- def __add__(self, other):
- return self.op("goofy")(other)
-
- Usage::
-
- >>> sometable = Table("sometable", metadata, Column("data", MyInt))
- >>> print sometable.c.data + 5
- sometable.data goofy :data_1
-
- New comparison methods and operations applied to :class:`.TypeEngine.Comparator`
- are made available on parent SQL constructs using a ``__getattr__()`` scheme::
-
- from sqlalchemy import Integer, func
-
- class MyInt(Integer):
- class comparator_factory(Integer.Comparator):
- def log(self, other):
- return func.log(self, other)
-
- E.g.::
-
- >>> print sometable.c.data.log(5)
- log(:log_1, :log_2)
-
- The :class:`.TypeEngine` associated with a particular :class:`.ColumnElement`
- is propagated during expression construction to the containing elements
- according to simple "adaptation" rules. An example of an "adaptation"
- would be adding two integers leads to a "binary" expression that is also
- of type integer::
-
- >>> from sqlalchemy.sql import column
- >>> from sqlalchemy.types import Integer
- >>> c1 = column('c1', Integer)
- >>> c2 = column('c2', Integer)
- >>> c1.type
- Integer()
- >>> (c1 + c2).type
- Integer()
-
- If the two columns above were compared using a boolean operator,
- the resulting type would instead be :class:`.Boolean`::
-
- >>> (c1 == c2).type
- Boolean()
+ See the documentation section :ref:`types_operators` for examples.
.. versionadded:: 0.8 The expression system was enhanced to support
customization of operators on a per-type level.