get_id_from_uuid()

This commit is contained in:
Kovid Goyal 2013-07-15 21:16:07 +05:30
parent abc9232016
commit cdf50da034
4 changed files with 13 additions and 0 deletions

View File

@ -1353,6 +1353,11 @@ class Cache(object):
self._mark_as_dirty(changed_books) self._mark_as_dirty(changed_books)
return changed_books return changed_books
@read_api
def lookup_by_uuid(self, uuid):
return self.fields['uuid'].table.lookup_by_uuid(uuid)
# }}} # }}}
class SortKey(object): # {{{ class SortKey(object): # {{{

View File

@ -153,6 +153,10 @@ class LibraryDatabase(object):
def refresh(self, field=None, ascending=True): def refresh(self, field=None, ascending=True):
self.data.refresh(field=field, ascending=ascending) self.data.refresh(field=field, ascending=ascending)
def get_id_from_uuid(self, uuid):
if uuid:
return self.new_api.lookup_by_uuid(uuid)
def add_listener(self, listener): def add_listener(self, listener):
''' '''
Add a listener. Will be called on change events with two arguments. Add a listener. Will be called on change events with two arguments.

View File

@ -137,6 +137,9 @@ class UUIDTable(OneToOneTable):
clean.add(val) clean.add(val)
return clean return clean
def lookup_by_uuid(self, uuid):
return self.uuid_to_id_map.get(uuid, None)
class CompositeTable(OneToOneTable): class CompositeTable(OneToOneTable):
def read(self, db): def read(self, db):

View File

@ -163,6 +163,7 @@ class LegacyTest(BaseTest):
for meth, args in { for meth, args in {
'get_next_series_num_for': [('A Series One',)], 'get_next_series_num_for': [('A Series One',)],
'get_id_from_uuid':[('ddddd',), (db.uuid(1, True),)],
'get_author_id': [('author one',), ('unknown',), ('xxxxx',)], 'get_author_id': [('author one',), ('unknown',), ('xxxxx',)],
'series_id': [(0,), (1,), (2,)], 'series_id': [(0,), (1,), (2,)],
'publisher_id': [(0,), (1,), (2,)], 'publisher_id': [(0,), (1,), (2,)],