add get_item convenience function to fetch Items by id

The beetfs project uses this to quickly get paths for items when reading them.
This commit is contained in:
Adrian Sampson 2010-07-21 11:26:43 -07:00
parent c62b1355f1
commit 7de294ba9f

View file

@ -884,6 +884,19 @@ class Library(BaseLibrary):
" ORDER BY artist, album, disc, track"
c = self.conn.execute(sql, subvals)
return ResultIterator(c, self)
# Convenience accessor.
def get_item(self, id):
"""Fetch an Item by its ID. Returns None if no match is found.
"""
c = self.conn.execute("SELECT * FROM items WHERE id=?", (id,))
it = ResultIterator(c, self)
try:
return it.next()
except StopIteration:
return None
# Album-level data.