# Copyright 2021 (c) Anna Schumaker. # # Table: artists # +----------+------+------+ # | artistid | name | sort | # +----------+------+------+ # # Index: artist_index # +------------------+ # | name -> artistid | # +------------------+ from . import album from . import execute from . import objects class Artist(objects.Tag): def do_get_column(self, column): 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): objects.Table.__init__(self, "artists", Artist) def do_create(self): execute("CREATE TABLE IF NOT EXISTS artists " "(artistid INTEGER PRIMARY KEY, " " name TEXT UNIQUE, " " sort TEXT)") execute("CREATE INDEX IF NOT EXISTS artist_index " "ON artists(name)") def do_insert(self, name, sort): return execute("INSERT INTO artists (name, sort) " "VALUES (?, ?)", (name, sort.casefold())) def do_delete(self, artist): return execute("DELETE FROM artists WHERE artistid=?", [ int(artist) ]) def do_get(self, rowid): return execute("SELECT artistid FROM artists " "WHERE artistid=?", [ rowid ]) def do_lookup(self, name, sort=None): return execute("SELECT artistid FROM artists " "WHERE name=?", [ name ]) Table = ArtistTable()