50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
|
# Copyright 2021 (c) Anna Schumaker.
|
||
|
#
|
||
|
# Table: artists
|
||
|
# +----------+------+------+
|
||
|
# | artistid | name | sort |
|
||
|
# +----------+------+------+
|
||
|
#
|
||
|
# Index: artist_index
|
||
|
# +------------------+
|
||
|
# | name -> artistid |
|
||
|
# +------------------+
|
||
|
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 ])
|
||
|
|
||
|
|
||
|
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()
|