01-22-2023, 12:59 AM | #1 |
Addict
Posts: 287
Karma: 2534928
Join Date: Nov 2022
Location: Canada
Device: Kobo Aura 2
|
Storing key-value metadata (for books, and for a whole library)
Suppose I have lots of key-value metadata that I wish to store for one or more books in my library. I do not know in advance what the keys will be, and there may be many of them, hundreds or thousands. The keys are small (word-sized) strings, and the values are integers.
Is there a better way of storing this information than as JSON-encoded data in a long-text (like comments) column? Suppose further that I wish to store a similar set of key-value data, scoped to my whole library (or possibly one virtual library), rather than any one particular book. Does the Calibre plugin API offer any way of storing metadata for a library, instead of for a single book? Thank you in advance. |
01-22-2023, 04:46 AM | #2 |
creator of calibre
Posts: 44,569
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
use set_pref with a namespace of your plugin import name, to store library wide metadata.
There is no facility for storing per book key/value metadata with arbitrary key sets other than identifiers. But you probably shouldn't overload those as that is likely to affect performance in many places. You can simply create a new table in the sqlite database (use a unique table name) or use a custom column storing the key values serialized to text. |
01-22-2023, 07:22 AM | #3 |
Grand Sorcerer
Posts: 12,043
Karma: 7548549
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Depending on what you want to do book-by-book, the API db.cache.(add_custom_book_data(), get_custom_book_data(), delete_custom_book_data(), and get_ids_for_custom_book_data()) might do the job. These let you store and retrieve more-or-less arbitrary data on a book-by-book basis. Internally calibre uses a table with three columns (book_id, data_name, data_val), where data_val is the json representation of the data.
You could store a python dict of your key:value pairs. If needed, you could give users access to the data via Python stored templates. The template would load the dict and return the desired value(s). |
01-22-2023, 10:24 AM | #4 |
creator of calibre
Posts: 44,569
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Yes add_custom_data might work, I forgot about that
|
01-22-2023, 11:55 AM | #5 |
Addict
Posts: 287
Karma: 2534928
Join Date: Nov 2022
Location: Canada
Device: Kobo Aura 2
|
This is SO helpful! Thank you very much Charles and Kovid!
|
Tags |
columns, dictionary, library metadata, mapping type |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Pros & Cons of storing library on mac's SSD vs. storing on external drive? | stan999 | Library Management | 16 | 04-10-2020 11:18 AM |
Storing library on external drive? | csg1964 | Library Management | 2 | 03-21-2015 08:06 PM |
Can we stop storing metadata in the filesystem please? | Don Edwards | Library Management | 23 | 10-03-2014 05:30 PM |
Glo Storing books on SD cards | GeoffR | Kobo Reader | 8 | 12-14-2012 01:45 AM |
storing books | rogerperk | Nook Color & Nook Tablet | 5 | 12-26-2010 11:01 PM |