db: Give Artists a function for listing their Albums

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-08-17 16:48:33 -04:00
parent 6a1713630b
commit 94f08dcd06
2 changed files with 12 additions and 0 deletions

View File

@ -9,6 +9,7 @@
# +------------------+
# | name -> artistid |
# +------------------+
from . import album
from . import execute
from . import objects
@ -17,6 +18,11 @@ class Artist(objects.Tag):
return execute(f"SELECT {column} FROM artists "
"WHERE artistid=?", [ self.rowid ])
def albums(self):
cursor = execute(f"SELECT albumid FROM albums "
"WHERE artistid=?", [ self.rowid ])
return [ album.Album(row["albumid"]) for row in cursor.fetchall() ]
class ArtistTable(objects.Table):
def __init__(self):

View File

@ -49,3 +49,9 @@ class TestArtistTable(unittest.TestCase):
artist = db.artist.Table.insert("Test Artist", "Test Sort")
self.assertEqual(db.artist.Table.lookup("Test Artist"), artist)
self.assertIsNone(db.artist.Table.lookup("none"))
def test_artist_albums(self):
artist = db.artist.Table.find("Test Artist", "Test Sort")
a = db.album.Table.find(artist, "A")
b = db.album.Table.find(artist, "B")
self.assertEqual(artist.albums(), [ a, b ])