And populate the table with some default playlist values. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
# Copyright 2021 (c) Anna Schumaker.
|
|
#
|
|
# Table: playlists
|
|
# +------ ---+------+------+
|
|
# | playlistid | name | sort |
|
|
# +-------- -+------+------+
|
|
#
|
|
# Index: playlist_index
|
|
# +--------------------+
|
|
# | name -> playlistid |
|
|
# +--------------------+
|
|
from . import execute
|
|
from . import executemany
|
|
from . import objects
|
|
from . import track
|
|
|
|
Default = [ "Collection", "Favorites", "New Tracks",
|
|
"Previous", "Queued Tracks" ]
|
|
|
|
|
|
class Playlist(objects.Tag):
|
|
def do_get_column(self, column):
|
|
return execute(f"SELECT {column} FROM playlists "
|
|
"WHERE playlistid=?", [ self.rowid ])
|
|
|
|
|
|
class PlaylistTable(objects.Table):
|
|
def __init__(self):
|
|
objects.Table.__init__(self, "playlists", Playlist)
|
|
|
|
def do_create(self):
|
|
execute("CREATE TABLE IF NOT EXISTS playlists "
|
|
"(playlistid INTEGER PRIMARY KEY, "
|
|
" name TEXT UNIQUE, "
|
|
" sort TEXT)")
|
|
execute("CREATE INDEX IF NOT EXISTS playlist_index "
|
|
"ON playlists(name)")
|
|
executemany("INSERT OR IGNORE INTO playlists (name, sort) "
|
|
"VALUES (?, ?)",
|
|
[ (p, p.casefold()) for p in Default ])
|
|
|
|
def do_insert(self, name):
|
|
return execute("INSERT INTO playlists (name, sort) "
|
|
"VALUES (?, ?)", (name, name.casefold()))
|
|
|
|
def do_delete(self, playlist):
|
|
return execute("DELETE FROM playlists WHERE playlistid=?", [ int(playlist) ])
|
|
|
|
def do_get(self, rowid):
|
|
return execute("SELECT playlistid FROM playlists "
|
|
"WHERE playlistid=?", [ rowid ])
|
|
|
|
def do_lookup(self, name):
|
|
return execute("SELECT playlistid FROM playlists "
|
|
"WHERE name=?", [ name ])
|
|
|
|
|
|
Table = PlaylistTable()
|