[SQL-CVS] r946 - in trunk/SQLObject: docs sqlobject
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2005-08-27 09:20:28
|
Author: ianb Date: 2005-08-27 09:20:16 +0000 (Sat, 27 Aug 2005) New Revision: 946 Modified: trunk/SQLObject/docs/News.txt trunk/SQLObject/sqlobject/sresults.py Log: Made select results aggressively fetch objects, instead of lazily Modified: trunk/SQLObject/docs/News.txt =================================================================== --- trunk/SQLObject/docs/News.txt 2005-08-25 16:54:35 UTC (rev 945) +++ trunk/SQLObject/docs/News.txt 2005-08-27 09:20:16 UTC (rev 946) @@ -17,7 +17,16 @@ .. _Inheritance.html: Inheritance.html +Other Changes +------------- +* When iterating over select results, a list is now immediately + created with the full list of instances being selected. Before + instances were created on demand, as select results were + pulled out row-by-row. The previous lazy behavior is available with + the method ``lazyIter``, used like ``for obj in + MyClass.select().lazyIter(): ...``. + SQLObject 0.6.1 =============== Modified: trunk/SQLObject/sqlobject/sresults.py =================================================================== --- trunk/SQLObject/sqlobject/sresults.py 2005-08-25 16:54:35 UTC (rev 945) +++ trunk/SQLObject/sqlobject/sresults.py 2005-08-27 09:20:16 UTC (rev 946) @@ -143,6 +143,16 @@ return list(self.clone(start=start, end=start+1))[0] def __iter__(self): + # @@: This could be optimized, using a simpler algorithm + # since we don't have to worry about garbage collection, + # etc., like we do with .lazyIter() + return iter(list(self.lazyIter())) + + def lazyIter(self): + """ + Returns an iterator that will lazily pull rows out of the + database and return SQLObject instances + """ conn = self._getConnection() return conn.iterSelect(self) |