def select(id): album = None sql = "SELECT * FROM albums WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: artist = artist_repo.select(result['artist_id']) album = Album(result["name"], result["genre"], artist, result["id"]) return album
def select_all(): albums = [] sql = "SELECT * FROM albums" results = run_sql(sql) for row in results: artist = artist_repo.select(row['artist_id']) album = Album(row['name'], row['genre'], row['id'], artist) albums.append(album) return albums
res = album_repo.select_all() for album in res: print(album.__dict__) res = artist_repo.select_all() for artist in res: print(artist.__dict__) res = artist_repo.albums(artist_2) for album in res: print(album.__dict__) res = album_repo.artist(album_1) print(res.__dict__) artist_4 = Artist("Mikey", "Boy", 1) artist_repo.update(artist_4) res = artist_repo.select_all() for artist in res: print(artist.__dict__) album_repo.delete(1) res = album_repo.select_all() for album in res: print(album.__dict__) found_artist = artist_repo.select(2) print(found_artist.__dict__) # pdb.set_trace()