pub trait Database: Sync + Send {
Show 14 methods // Required methods fn new(db_path: &str) -> Result<Self, Error> where Self: Sized; fn create_database_tables(&self) -> Result<(), Error>; fn drop_database_tables(&self) -> Result<(), Error>; fn load_persistent_torrents<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<Vec<(InfoHash, u32)>, Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn save_persistent_torrent<'life0, 'life1, 'async_trait>( &'life0 self, info_hash: &'life1 InfoHash, completed: u32 ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn load_whitelist<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<Vec<InfoHash>, Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_info_hash_from_whitelist<'life0, 'life1, 'async_trait>( &'life0 self, info_hash: &'life1 InfoHash ) -> Pin<Box<dyn Future<Output = Result<Option<InfoHash>, Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn add_info_hash_to_whitelist<'life0, 'async_trait>( &'life0 self, info_hash: InfoHash ) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn remove_info_hash_from_whitelist<'life0, 'async_trait>( &'life0 self, info_hash: InfoHash ) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn load_keys<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<Vec<ExpiringKey>, Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_key_from_keys<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 Key ) -> Pin<Box<dyn Future<Output = Result<Option<ExpiringKey>, Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn add_key_to_keys<'life0, 'life1, 'async_trait>( &'life0 self, auth_key: &'life1 ExpiringKey ) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn remove_key_from_keys<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 Key ) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; // Provided method fn is_info_hash_whitelisted<'life0, 'life1, 'async_trait>( &'life0 self, info_hash: &'life1 InfoHash ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... }
}
Expand description

The persistence trait. It contains all the methods to interact with the database.

Required Methods§

source

fn new(db_path: &str) -> Result<Self, Error>where Self: Sized,

It instantiates a new database driver.

Errors

Will return r2d2::Error if db_path is not able to create a database.

source

fn create_database_tables(&self) -> Result<(), Error>

It generates the database tables. SQL queries are hardcoded in the trait implementation.

Context: Schema
Errors

Will return Error if unable to create own tables.

source

fn drop_database_tables(&self) -> Result<(), Error>

It drops the database tables.

Context: Schema
Errors

Will return Err if unable to drop tables.

source

fn load_persistent_torrents<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<Vec<(InfoHash, u32)>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

It loads the torrent metrics data from the database.

It returns an array of tuples with the torrent InfoHash and the completed counter which is the number of times the torrent has been downloaded. See Entry::completed.

Context: Torrent Metrics
Errors

Will return Err if unable to load.

source

fn save_persistent_torrent<'life0, 'life1, 'async_trait>( &'life0 self, info_hash: &'life1 InfoHash, completed: u32 ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

It saves the torrent metrics data into the database.

Context: Torrent Metrics
Errors

Will return Err if unable to save.

source

fn load_whitelist<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<Vec<InfoHash>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

It loads the whitelisted torrents from the database.

Context: Whitelist
Errors

Will return Err if unable to load.

source

fn get_info_hash_from_whitelist<'life0, 'life1, 'async_trait>( &'life0 self, info_hash: &'life1 InfoHash ) -> Pin<Box<dyn Future<Output = Result<Option<InfoHash>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

It checks if the torrent is whitelisted.

It returns Some(InfoHash) if the torrent is whitelisted, None otherwise.

Context: Whitelist
Errors

Will return Err if unable to load.

source

fn add_info_hash_to_whitelist<'life0, 'async_trait>( &'life0 self, info_hash: InfoHash ) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

It adds the torrent to the whitelist.

Context: Whitelist
Errors

Will return Err if unable to save.

source

fn remove_info_hash_from_whitelist<'life0, 'async_trait>( &'life0 self, info_hash: InfoHash ) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

It removes the torrent from the whitelist.

Context: Whitelist
Errors

Will return Err if unable to save.

source

fn load_keys<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<Vec<ExpiringKey>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

It loads the expiring authentication keys from the database.

Context: Authentication Keys
Errors

Will return Err if unable to load.

source

fn get_key_from_keys<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 Key ) -> Pin<Box<dyn Future<Output = Result<Option<ExpiringKey>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

It gets an expiring authentication key from the database.

It returns Some(ExpiringKey) if a ExpiringKey with the input Key exists, None otherwise.

Context: Authentication Keys
Errors

Will return Err if unable to load.

source

fn add_key_to_keys<'life0, 'life1, 'async_trait>( &'life0 self, auth_key: &'life1 ExpiringKey ) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

It adds an expiring authentication key to the database.

Context: Authentication Keys
Errors

Will return Err if unable to save.

source

fn remove_key_from_keys<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 Key ) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

It removes an expiring authentication key from the database.

Context: Authentication Keys
Errors

Will return Err if unable to load.

Provided Methods§

source

fn is_info_hash_whitelisted<'life0, 'life1, 'async_trait>( &'life0 self, info_hash: &'life1 InfoHash ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

It checks if the torrent is whitelisted.

Context: Whitelist
Errors

Will return Err if unable to load.

Implementors§