summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaëtan de Menten <gdementen@gmail.com>2007-04-30 09:36:12 +0000
committerGaëtan de Menten <gdementen@gmail.com>2007-04-30 09:36:12 +0000
commit39947e1f5d131775e7beef7773d9905706dced64 (patch)
treef856f33414f346ce35b6bb85c305e5d52870dcb4
parentdfc633b08b49f8b7ed083af3b274d28df2fbe316 (diff)
downloadsqlalchemy-39947e1f5d131775e7beef7773d9905706dced64.tar.gz
- docstring improvements in query
- added support for __getitem__ on OrderedSet
-rw-r--r--lib/sqlalchemy/orm/query.py24
-rw-r--r--lib/sqlalchemy/util.py3
2 files changed, 21 insertions, 6 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index 355ba68f7..be299d200 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -737,7 +737,8 @@ class Query(object):
return q
def select_from(self, from_obj):
- """Set the `from_obj` parameter of the query.
+ """Set the `from_obj` parameter of the query and return the newly
+ resulting ``Query``.
`from_obj` is a list of one or more tables.
"""
@@ -764,14 +765,15 @@ class Query(object):
if isinstance(item, slice):
start = item.start
stop = item.stop
+ # if we slice from the end we need to execute the query
if (isinstance(start, int) and start < 0) or \
(isinstance(stop, int) and stop < 0):
return list(self)[item]
else:
res = self._clone()
if start is not None and stop is not None:
- res._offset = (self._offset or 0)+ start
- res._limit = stop-start
+ res._offset = (self._offset or 0) + start
+ res._limit = stop - start
elif start is None and stop is not None:
res._limit = stop
elif start is not None and stop is None:
@@ -784,17 +786,23 @@ class Query(object):
return list(self[item:item+1])[0]
def limit(self, limit):
- """Apply a ``LIMIT`` to the query."""
+ """Apply a ``LIMIT`` to the query and return the newly resulting
+ ``Query``.
+ """
return self[:limit]
def offset(self, offset):
- """Apply an ``OFFSET`` to the query."""
+ """Apply an ``OFFSET`` to the query and return the newly resulting
+ ``Query``.
+ """
return self[offset:]
def distinct(self):
- """Apply a ``DISTINCT`` to the query."""
+ """Apply a ``DISTINCT`` to the query and return the newly resulting
+ ``Query``.
+ """
new = self._clone()
new._distinct = True
@@ -809,6 +817,10 @@ class Query(object):
return list(self)
def scalar(self):
+ """Return the first result of this ``Query``.
+
+ This results in an execution of the underlying query.
+ """
if self._col is None or self._func is None:
return self[0]
else:
diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py
index d4627974b..e4b0efad4 100644
--- a/lib/sqlalchemy/util.py
+++ b/lib/sqlalchemy/util.py
@@ -331,6 +331,9 @@ class OrderedSet(Set):
super(OrderedSet, self).clear()
self._list=[]
+ def __getitem__(self, key):
+ return self._list[key]
+
def __iter__(self):
return iter(self._list)