From 2a9b2cd0954cf97d5c31e545d1d0734f3e131fae Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 11 Sep 2020 23:51:57 -0700 Subject: [PATCH] Add methods PDB.get_thing_count for all thing types. --- etiquette/photodb.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 44de650..81942bb 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -46,6 +46,9 @@ class PDBAlbumMixin: def get_album_by_id(self, id): return self.get_thing_by_id('album', id) + def get_album_count(self): + return self.sql_select_one('SELECT COUNT(id) FROM albums')[0] + def get_albums(self): yield from self.get_things(thing_type='album') @@ -125,6 +128,9 @@ class PDBBookmarkMixin: def get_bookmark(self, id): return self.get_thing_by_id('bookmark', id) + def get_bookmark_count(self): + return self.sql_select_one('SELECT COUNT(id) FROM bookmarks')[0] + def get_bookmarks(self): yield from self.get_things(thing_type='bookmark') @@ -355,6 +361,9 @@ class PDBPhotoMixin: photo = self.get_cached_instance('photo', photo_row) return photo + def get_photo_count(self): + return self.sql_select_one('SELECT COUNT(id) FROM photos')[0] + def get_photos_by_id(self, ids): return self.get_things_by_id('photo', ids) @@ -1082,6 +1091,9 @@ class PDBTagMixin: tag = self.get_cached_instance('tag', tag_row) return tag + def get_tag_count(self): + return self.sql_select_one('SELECT COUNT(id) FROM tags')[0] + def get_tags(self): ''' Yield all Tags in the database. @@ -1198,6 +1210,9 @@ class PDBUserMixin: else: raise exceptions.NoSuchUser(username or id) + def get_user_count(self): + return self.sql_select_one('SELECT COUNT(id) FROM users')[0] + def get_user_id_or_none(self, user_obj_or_id): ''' For methods that create photos, albums, etc., we sometimes associate