summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/assignmapper.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-03-10 02:49:12 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-03-10 02:49:12 +0000
commitb2e04755cc5f382596fb174c7381f60dd2972d94 (patch)
treebafe994b93bd2a57633c3b9ffedf39d725844350 /lib/sqlalchemy/ext/assignmapper.py
parent585eacba010eee5be719074fa31d3e8b41cc79a9 (diff)
downloadsqlalchemy-b2e04755cc5f382596fb174c7381f60dd2972d94.tar.gz
- the full featureset of the SelectResults extension has been merged
into a new set of methods available off of Query. These methods all provide "generative" behavior, whereby the Query is copied and a new one returned with additional criterion added. The new methods include: filter() - applies select criterion to the query filter_by() - applies "by"-style criterion to the query avg() - return the avg() function on the given column join() - join to a property (or across a list of properties) outerjoin() - like join() but uses LEFT OUTER JOIN limit()/offset() - apply LIMIT/OFFSET range-based access which applies limit/offset: session.query(Foo)[3:5] distinct() - apply DISTINCT list() - evaluate the criterion and return results no incompatible changes have been made to Query's API and no methods have been deprecated. Existing methods like select(), select_by(), get(), get_by() all execute the query at once and return results like they always did. join_to()/join_via() are still there although the generative join()/outerjoin() methods are easier to use. - the return value for multiple mappers used with instances() now returns a cartesian product of the requested list of mappers, represented as a list of tuples. this corresponds to the documented behavior. So that instances match up properly, the "uniquing" is disabled when this feature is used. - strings and columns can also be sent to the *args of instances() where those exact result columns will be part of the result tuples. - query() method is added by assignmapper. this helps with navigating to all the new generative methods on Query.
Diffstat (limited to 'lib/sqlalchemy/ext/assignmapper.py')
-rw-r--r--lib/sqlalchemy/ext/assignmapper.py1
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/sqlalchemy/ext/assignmapper.py b/lib/sqlalchemy/ext/assignmapper.py
index 178f150e5..aee96f06e 100644
--- a/lib/sqlalchemy/ext/assignmapper.py
+++ b/lib/sqlalchemy/ext/assignmapper.py
@@ -34,6 +34,7 @@ def assign_mapper(ctx, class_, *args, **kwargs):
extension = ctx.mapper_extension
m = mapper(class_, extension=extension, *args, **kwargs)
class_.mapper = m
+ class_.query = classmethod(lambda cls: Query(class_, session=ctx.current))
for name in ['get', 'select', 'select_by', 'selectfirst', 'selectfirst_by', 'selectone', 'get_by', 'join_to', 'join_via', 'count', 'count_by', 'options', 'instances']:
monkeypatch_query_method(ctx, class_, name)
for name in ['flush', 'delete', 'expire', 'refresh', 'expunge', 'merge', 'save', 'update', 'save_or_update']: