The database functions module provides thread-safe operations for storing and retrieving TorBox download metadata using TinyDB as a local cache.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/torbox-app/torbox-media-center/llms.txt
Use this file to discover all available pages before exploring further.
Database connection management
getDatabase
The database name (corresponds to
{name}.json file).The TinyDB database instance, or None if connection fails.
- Creates a single shared connection per database name
- Automatically creates the database file if it doesn’t exist
- Thread-safe initialization using a global lock
getDatabaseLock
The database name.
The lock object for the database, or None if the database doesn’t exist.
Data operations
insertData
The data dictionary to insert.
The database type/name (e.g., “torrents”, “usenet”, “webdl”).
A tuple containing:
success(bool): True if insertion succeededmessage(str): Success or error message
getAllData
The database type/name to query.
A tuple containing:
data(list | None): List of all records, or None on errorsuccess(bool): True if retrieval succeededmessage(str): Success or error message
clearDatabase
The database type/name to clear.
A tuple containing:
success(bool): True if clearing succeededmessage(str): Success or error message
Connection cleanup
closeDatabase
The database name to close.
A tuple containing:
success(bool): True if closing succeeded or database wasn’t openmessage(str): Success or error message
closeAllDatabases
A tuple containing:
success(bool): Always Truemessage(str): Summary message indicating number of connections closed
Thread safety model
All database operations in this module are thread-safe:- Global lock: Protects the connection pool during database initialization
- Per-database locks: Each database has its own lock for data operations
- Automatic locking: All data operations acquire locks before accessing the database
Database storage format
Databases are stored as JSON files:torrents.json- Torrent download cacheusenet.json- Usenet download cachewebdl.json- WebDL download cache
process_file in the TorBox functions module.