pub struct Database { /* private fields */ }Expand description
Database connection pool and operations.
Implementations§
Source§impl Database
impl Database
Sourcepub fn with_config(config: DatabaseConfig) -> Result<Self>
pub fn with_config(config: DatabaseConfig) -> Result<Self>
Open a database with the given configuration.
Sourcepub fn conn(&self) -> Result<PooledConnection<SqliteConnectionManager>>
pub fn conn(&self) -> Result<PooledConnection<SqliteConnectionManager>>
Get a connection from the pool.
Sourcepub fn initialize(&self) -> Result<()>
pub fn initialize(&self) -> Result<()>
Initialize the database schema.
Sourcepub fn is_initialized(&self) -> Result<bool>
pub fn is_initialized(&self) -> Result<bool>
Check if the database is initialized.
Sourcepub fn migrate_if_needed(&self) -> Result<()>
pub fn migrate_if_needed(&self) -> Result<()>
Migrate the database schema if needed.
Call this on an existing database to upgrade it to the current schema version.
Sourcepub fn begin_transaction(&self) -> Result<Transaction>
pub fn begin_transaction(&self) -> Result<Transaction>
Begin a transaction for bulk operations.
Sourcepub fn insert_record(&self, record: &UlsRecord) -> Result<()>
pub fn insert_record(&self, record: &UlsRecord) -> Result<()>
Insert a ULS record into the database.
Sourcepub fn get_license_by_callsign(&self, callsign: &str) -> Result<Option<License>>
pub fn get_license_by_callsign(&self, callsign: &str) -> Result<Option<License>>
Look up a license by call sign.
Sourcepub fn get_licenses_by_frn(&self, frn: &str) -> Result<Vec<License>>
pub fn get_licenses_by_frn(&self, frn: &str) -> Result<Vec<License>>
Look up all licenses by FRN (FCC Registration Number).
Sourcepub fn get_stats(&self) -> Result<LicenseStats>
pub fn get_stats(&self) -> Result<LicenseStats>
Get database statistics.
Sourcepub fn count_by_service(&self, service_codes: &[&str]) -> Result<u64>
pub fn count_by_service(&self, service_codes: &[&str]) -> Result<u64>
Count licenses by radio service code(s). Pass service codes like [“HA”, “HV”] for amateur or [“ZA”] for GMRS.
Sourcepub fn set_last_updated(&self, timestamp: &str) -> Result<()>
pub fn set_last_updated(&self, timestamp: &str) -> Result<()>
Set the last updated timestamp.
Sourcepub fn get_imported_etag(&self, service: &str) -> Result<Option<String>>
pub fn get_imported_etag(&self, service: &str) -> Result<Option<String>>
Get the ETag of the last imported file for a service.
Sourcepub fn set_imported_etag(&self, service: &str, etag: &str) -> Result<()>
pub fn set_imported_etag(&self, service: &str, etag: &str) -> Result<()>
Set the ETag of the last imported file for a service.
Sourcepub fn has_record_type(&self, service: &str, record_type: &str) -> Result<bool>
pub fn has_record_type(&self, service: &str, record_type: &str) -> Result<bool>
Check if a record type has been imported for a service.
Sourcepub fn get_imported_types(&self, service: &str) -> Result<Vec<String>>
pub fn get_imported_types(&self, service: &str) -> Result<Vec<String>>
Get list of imported record types for a service.
Sourcepub fn mark_imported(
&self,
service: &str,
record_type: &str,
count: usize,
) -> Result<()>
pub fn mark_imported( &self, service: &str, record_type: &str, count: usize, ) -> Result<()>
Mark record type as imported for a service.
Sourcepub fn clear_import_status(&self, service: &str) -> Result<()>
pub fn clear_import_status(&self, service: &str) -> Result<()>
Clear import status for a service (used when doing full re-import).
Sourcepub fn get_imported_count(
&self,
service: &str,
record_type: &str,
) -> Result<Option<usize>>
pub fn get_imported_count( &self, service: &str, record_type: &str, ) -> Result<Option<usize>>
Get record count for an imported record type.
Sourcepub fn get_last_updated(&self) -> Result<Option<String>>
pub fn get_last_updated(&self) -> Result<Option<String>>
Get the last updated timestamp for a service.
Sourcepub fn get_freshness(
&self,
service: &str,
threshold_days: i64,
) -> Result<DataFreshness>
pub fn get_freshness( &self, service: &str, threshold_days: i64, ) -> Result<DataFreshness>
Get data freshness information for a service.
Sourcepub fn is_stale(&self, service: &str, threshold_days: i64) -> Result<bool>
pub fn is_stale(&self, service: &str, threshold_days: i64) -> Result<bool>
Check if data for a service is stale.
Sourcepub fn record_applied_patch(
&self,
service: &str,
patch_date: NaiveDate,
weekday: &str,
etag: Option<&str>,
record_count: Option<usize>,
) -> Result<()>
pub fn record_applied_patch( &self, service: &str, patch_date: NaiveDate, weekday: &str, etag: Option<&str>, record_count: Option<usize>, ) -> Result<()>
Record that a daily patch has been applied.
Sourcepub fn get_applied_patches(&self, service: &str) -> Result<Vec<AppliedPatch>>
pub fn get_applied_patches(&self, service: &str) -> Result<Vec<AppliedPatch>>
Get all applied patches for a service since last weekly.
Sourcepub fn clear_applied_patches(&self, service: &str) -> Result<()>
pub fn clear_applied_patches(&self, service: &str) -> Result<()>
Clear applied patches for a service (called when new weekly is imported).