]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- docstring improvements in query
authorGaëtan de Menten <gdementen@gmail.com>
Mon, 30 Apr 2007 09:36:12 +0000 (09:36 +0000)
committerGaëtan de Menten <gdementen@gmail.com>
Mon, 30 Apr 2007 09:36:12 +0000 (09:36 +0000)
- added support for __getitem__ on OrderedSet

lib/sqlalchemy/orm/query.py
lib/sqlalchemy/util.py

index 355ba68f799f1e8a238c65d4c5475128f01999af..be299d2005eb7500bc4f3b5596fcf54487e7db03 100644 (file)
@@ -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:
index d4627974b558e2ab2c7b78846185d847c3e58df9..e4b0efad4b83838c491fe66e64043170a4e2dc5a 100644 (file)
@@ -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)