[CalendarServer-changes] [9646] CalendarServer/branches/users/glyph/q
source_changes at macosforge.org
source_changes at macosforge.org
Sat Aug 11 01:55:19 PDT 2012
Revision: 9646
http://trac.macosforge.org/projects/calendarserver/changeset/9646
Author: glyph at apple.com
Date: 2012-08-11 01:55:19 -0700 (Sat, 11 Aug 2012)
Log Message:
-----------
test and implement record query ordering
Modified Paths:
--------------
CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py
CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_record.py
Property Changed:
----------------
CalendarServer/branches/users/glyph/q/
Modified: CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py
===================================================================
--- CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py 2012-08-11 08:55:18 UTC (rev 9645)
+++ CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py 2012-08-11 08:55:19 UTC (rev 9646)
@@ -149,14 +149,17 @@
@classmethod
@inlineCallbacks
- def query(cls, txn, expr, order=None):
+ def query(cls, txn, expr, order=None, ascending=True):
"""
Query the table that corresponds to C{cls}, and return instances of
C{cls} corresponding to the rows that are returned from that table.
"""
tbl = cls.__tbl__
allColumns = list(tbl)
- slct = Select(allColumns, From=tbl, Where=expr)
+ kw = {}
+ if order is not None:
+ kw.update(OrderBy=order, Ascending=ascending)
+ slct = Select(allColumns, From=tbl, Where=expr, **kw)
rows = yield slct.on(txn)
selves = []
for row in rows:
Modified: CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_record.py
===================================================================
--- CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_record.py 2012-08-11 08:55:18 UTC (rev 9645)
+++ CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_record.py 2012-08-11 08:55:19 UTC (rev 9646)
@@ -175,5 +175,24 @@
self.assertEqual(records[1].beta, 356)
+ @inlineCallbacks
+ def test_orderedQuery(self):
+ """
+ L{Record.query} takes an 'order' argument which will allow the objects
+ returned to be ordered.
+ """
+ txn = self.pool.connection()
+ for beta, gamma in [(123, u"one"), (234, u"two"), (345, u"three"),
+ (356, u"three"), (456, u"four")]:
+ yield txn.execSQL("insert into ALPHA values (:1, :2)",
+ [beta, gamma])
+ records = yield TestRecord.query(txn, TestRecord.gamma == u"three",
+ TestRecord.beta)
+ self.assertEqual([record.beta for record in records], [345, 356])
+ records = yield TestRecord.query(txn, TestRecord.gamma == u"three",
+ TestRecord.beta, ascending=False)
+ self.assertEqual([record.beta for record in records], [356, 345])
+
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120811/fab42214/attachment.html>
More information about the calendarserver-changes
mailing list