Add count() support to find_streams
Returns [{'count': num_streams}] Change-Id: I37e7fc462a14dda793ac5c231439ed7d5e5ee523
This commit is contained in:
parent
c5f0eca828
commit
460f8231ee
@ -446,4 +446,6 @@ class TestDB(unittest.TestCase):
|
||||
with self.assertRaises(db.NoSuchStreamError):
|
||||
self.db.get_stream_by_id(1)
|
||||
|
||||
|
||||
def test_find_stream_count(self):
|
||||
count = self.db.find_streams(count=True)
|
||||
self.assertEqual([{'count': 8}], count)
|
||||
|
@ -235,7 +235,8 @@ class DBInterface(object):
|
||||
return stream
|
||||
|
||||
@sessioned
|
||||
def find_streams(self, stream_id=None, state=None, older_than=None, younger_than=None,
|
||||
def find_streams(self, count=False, stream_id=None, state=None,
|
||||
older_than=None, younger_than=None,
|
||||
name=None, distinguishing_traits=None,
|
||||
session=None, include_events=False):
|
||||
q = session.query(models.Stream)
|
||||
@ -254,6 +255,11 @@ class DBInterface(object):
|
||||
q = q.filter(models.Stream.distinguished_by.any(and_(
|
||||
models.DistinguishingTrait.name == name,
|
||||
models.DistinguishingTrait.value == val)))
|
||||
|
||||
if count:
|
||||
q = q.count()
|
||||
return [{"count": q}]
|
||||
|
||||
stream_info = []
|
||||
for stream in q.all():
|
||||
info = stream.as_dict
|
||||
|
Loading…
x
Reference in New Issue
Block a user