diff options
author | Michaël Ball <michael.ball@gmail.com> | 2015-11-27 19:24:36 +0000 |
---|---|---|
committer | Michaël Ball <michael.ball@gmail.com> | 2015-11-27 19:24:36 +0000 |
commit | 52791f111e9ee885389377a91cab44faa61c32b5 (patch) | |
tree | 6f926568f79408bd7c7ed0a017b801a04e990ace /models/album.py | |
parent | 6b5c87d5c35ebbac6f7fbcac1a722bd0b3148e04 (diff) |
Better library management
Diffstat (limited to 'models/album.py')
-rw-r--r-- | models/album.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/models/album.py b/models/album.py index 216b615..9ca3798 100644 --- a/models/album.py +++ b/models/album.py @@ -134,3 +134,26 @@ class Album(): ) return albums + + def all(order="album.id", direction="ASC", limit=None, offset=None): + db = DbManager() + cursor = db.cursor() + albums = [] + + select_string = """SELECT * FROM album LEFT JOIN album_artist ON + album_artist.album_id = album.id LEFT JOIN artist ON + album_artist.artist_id = artist.id ORDER BY %s %s""" % (order, + direction) + + if limit is not None and offset is not None: + select_string = " ".join((select_string, + "LIMIT %s OFFSET %s" % (limit, offset))) + + result = cursor.execute(select_string) + + for row in result: + albums.append( + Album(id=row[0], name=row[1], date=row[2]) + ) + + return albums |