Database
Object Hierarchy:
Description:
public class Database
Manages SQLite database connections with in-memory storage and file backup.
The Database class provides a wrapper around SQLite that uses an in-memory database for performance, with the ability to backup to and
restore from a file. It maintains a schema cache to avoid repeated schema queries.
The database is configured for serialized access mode, allowing safe multi-threaded access.
Thread safety is ensured via a mutex that protects all database operations, allowing safe concurrent access from multiple threads (e.g.,
main thread and background async query threads).
Content:
Properties:
- public int countdown { get; }
Steps remaining before a deferred disk backup runs (reset to 5 on each
coalesced backupDB request while a timer is armed).
- public uint countdown_id { get; }
GLib timeout source id for the repeating backup countdown tick. Zero
when no timer is armed.
- public string filename { get; }
The filename used for backup and restore operations.
- public bool is_dirty { get; set; }
Whether the database has unsaved changes (dirty flag).
- public int64 last_backup { get; }
Unix time of the last successful disk backup (backup_real). Zero
before any backup has completed.
Creation methods:
Methods:
Fields:
- public Database db
The underlying SQLite database connection.
- public Mutex db_mutex
Mutex to protect database operations from concurrent access. All
operations that use `db` must lock this mutex first.
- public HashMap<string,ArrayList<Schema>> schema_cache
Cache of table schemas to avoid repeated PRAGMA queries.