mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Improvements in the plugin data store API
This commit is contained in:
commit
bc4ad91b4c
@ -3217,7 +3217,6 @@ books_series_link feeds
|
|||||||
if callable(callback):
|
if callable(callback):
|
||||||
if callback(''):
|
if callback(''):
|
||||||
break
|
break
|
||||||
|
|
||||||
return duplicates
|
return duplicates
|
||||||
|
|
||||||
def add_custom_book_data(self, book_id, name, val):
|
def add_custom_book_data(self, book_id, name, val):
|
||||||
@ -3226,12 +3225,19 @@ books_series_link feeds
|
|||||||
raise ValueError('add_custom_book_data: no such book_id %d'%book_id)
|
raise ValueError('add_custom_book_data: no such book_id %d'%book_id)
|
||||||
# Do the json encode first, in case it throws an exception
|
# Do the json encode first, in case it throws an exception
|
||||||
s = json.dumps(val, default=to_json)
|
s = json.dumps(val, default=to_json)
|
||||||
self.conn.execute('DELETE FROM books_plugin_data WHERE book=? AND name=?',
|
self.conn.execute('''INSERT OR REPLACE INTO books_plugin_data(book, name, val)
|
||||||
(book_id, name))
|
|
||||||
self.conn.execute('''INSERT INTO books_plugin_data(book, name, val)
|
|
||||||
VALUES(?, ?, ?)''', (book_id, name, s))
|
VALUES(?, ?, ?)''', (book_id, name, s))
|
||||||
self.commit()
|
self.commit()
|
||||||
|
|
||||||
|
def add_multiple_custom_book_data(self, name, vals, delete_first=False):
|
||||||
|
if delete_first:
|
||||||
|
self.conn.execute('DELETE FROM books_plugin_data WHERE name=?', (name, ))
|
||||||
|
self.conn.executemany(
|
||||||
|
'INSERT OR REPLACE INTO books_plugin_data (book, name, val) VALUES (?, ?, ?)',
|
||||||
|
[(book_id, name, json.dumps(val, default=to_json))
|
||||||
|
for book_id, val in vals.iteritems()])
|
||||||
|
self.commit()
|
||||||
|
|
||||||
def get_custom_book_data(self, book_id, name, default=None):
|
def get_custom_book_data(self, book_id, name, default=None):
|
||||||
try:
|
try:
|
||||||
s = self.conn.get('''select val FROM books_plugin_data
|
s = self.conn.get('''select val FROM books_plugin_data
|
||||||
@ -3243,11 +3249,29 @@ books_series_link feeds
|
|||||||
pass
|
pass
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
def get_all_custom_book_data(self, name, default=None):
|
||||||
|
try:
|
||||||
|
s = self.conn.get('''select book, val FROM books_plugin_data
|
||||||
|
WHERE name=?''', (name,))
|
||||||
|
if s is None:
|
||||||
|
return default
|
||||||
|
res = {}
|
||||||
|
for r in s:
|
||||||
|
res[r[0]] = json.loads(r[1], object_hook=from_json)
|
||||||
|
return res
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return default
|
||||||
|
|
||||||
def delete_custom_book_data(self, book_id, name):
|
def delete_custom_book_data(self, book_id, name):
|
||||||
self.conn.execute('DELETE FROM books_plugin_data WHERE book=? AND name=?',
|
self.conn.execute('DELETE FROM books_plugin_data WHERE book=? AND name=?',
|
||||||
(book_id, name))
|
(book_id, name))
|
||||||
self.commit()
|
self.commit()
|
||||||
|
|
||||||
|
def delete_all_custom_book_data(self, name):
|
||||||
|
self.conn.execute('DELETE FROM books_plugin_data WHERE name=?', (name, ))
|
||||||
|
self.commit()
|
||||||
|
|
||||||
def get_ids_for_custom_book_data(self, name):
|
def get_ids_for_custom_book_data(self, name):
|
||||||
s = self.conn.get('''SELECT book FROM books_plugin_data WHERE name=?''', (name,))
|
s = self.conn.get('''SELECT book FROM books_plugin_data WHERE name=?''', (name,))
|
||||||
return [x[0] for x in s]
|
return [x[0] for x in s]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user