[CalendarServer-changes] [15093] twext/trunk/twext/enterprise/dal
source_changes at macosforge.org
source_changes at macosforge.org
Thu Sep 3 13:38:35 PDT 2015
Revision: 15093
http://trac.calendarserver.org//changeset/15093
Author: cdaboo at apple.com
Date: 2015-09-03 13:38:35 -0700 (Thu, 03 Sep 2015)
Log Message:
-----------
Add method to return count of the number of records in the DB.
Modified Paths:
--------------
twext/trunk/twext/enterprise/dal/record.py
twext/trunk/twext/enterprise/dal/test/test_record.py
Modified: twext/trunk/twext/enterprise/dal/record.py
===================================================================
--- twext/trunk/twext/enterprise/dal/record.py 2015-09-03 20:38:04 UTC (rev 15092)
+++ twext/trunk/twext/enterprise/dal/record.py 2015-09-03 20:38:35 UTC (rev 15093)
@@ -31,8 +31,8 @@
from twisted.internet.defer import inlineCallbacks, returnValue
from twext.enterprise.dal.syntax import (
- Select, Tuple, Constant, ColumnSyntax, Insert, Update, Delete, SavepointAction
-)
+ Select, Tuple, Constant, ColumnSyntax, Insert, Update, Delete, SavepointAction,
+ Count, ALL_COLUMNS)
from twext.enterprise.util import parseSQLTimestamp
# from twext.enterprise.dal.syntax import ExpressionSyntax
@@ -594,6 +594,20 @@
@classmethod
+ @inlineCallbacks
+ def count(cls, transaction, where=None):
+ """
+ Count the number of rows in the table that corresponds to C{cls}.
+ """
+ rows = yield Select(
+ [Count(ALL_COLUMNS), ],
+ From=cls.table,
+ Where=where,
+ ).on(transaction)
+ returnValue(rows[0][0])
+
+
+ @classmethod
def updatesome(cls, transaction, where, **kw):
"""
Update rows matching the where expression from the table that corresponds to C{cls}.
Modified: twext/trunk/twext/enterprise/dal/test/test_record.py
===================================================================
--- twext/trunk/twext/enterprise/dal/test/test_record.py 2015-09-03 20:38:04 UTC (rev 15092)
+++ twext/trunk/twext/enterprise/dal/test/test_record.py 2015-09-03 20:38:35 UTC (rev 15093)
@@ -363,6 +363,23 @@
@inlineCallbacks
+ def test_count(self):
+ """
+ L{Record.count} will return count of the records
+ """
+ txn = self.pool.connection()
+ data = [(123, u"one"), (456, u"four"), (345, u"three"),
+ (234, u"two"), (356, u"three")]
+ for beta, gamma in data:
+ yield txn.execSQL("insert into ALPHA values (:1, :2)",
+ [beta, gamma])
+ self.assertEqual(
+ (yield TestRecord.count(txn)),
+ len(data)
+ )
+
+
+ @inlineCallbacks
def test_updatesome(self):
"""
L{Record.updatesome} will update all instances of the matching records.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150903/d6c14bb8/attachment.html>
More information about the calendarserver-changes
mailing list