View Single Post
Old 01-07-2021, 12:41 PM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,448
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
LibraryDatabase2 is obsolete. It works with the new database introduced in V4 because Kovid supplied a "legacy" replacement.

For all new code it is best to use something like this:
Code:
def init_cache(library_path):
   from calibre.db.backend import DB
   from calibre.db.cache import Cache
   backend = DB(library_path)  # other named parameters as needed
   cache = Cache(backend)
   cache.init()
   return cache
Use the methods in Cache.

For older code that uses methods in LibraryDatabase2, use something like this:
Code:
from calibre.db.legacy import LibraryDatabase
db = LibraryDatabase(library_path) # other named parameters as needed
In this case the methods in "Cache" are available via db.new_api.

I think the new_api attribute might be available in LibraryDatabase2 through some sort of monkeypatching, but I am not sure of that.

Last edited by chaley; 01-07-2021 at 12:58 PM. Reason: Changed parameter of LibraryDatabase
chaley is offline   Reply With Quote