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(&self) -> Result<PersistentTorrents, Error>;
fn save_persistent_torrent(
&self,
info_hash: &InfoHash,
downloaded: u32,
) -> Result<(), Error>;
fn load_whitelist(&self) -> Result<Vec<InfoHash>, Error>;
fn get_info_hash_from_whitelist(
&self,
info_hash: InfoHash,
) -> Result<Option<InfoHash>, Error>;
fn add_info_hash_to_whitelist(
&self,
info_hash: InfoHash,
) -> Result<usize, Error>;
fn remove_info_hash_from_whitelist(
&self,
info_hash: InfoHash,
) -> Result<usize, Error>;
fn load_keys(&self) -> Result<Vec<PeerKey>, Error>;
fn get_key_from_keys(&self, key: &Key) -> Result<Option<PeerKey>, Error>;
fn add_key_to_keys(&self, auth_key: &PeerKey) -> Result<usize, Error>;
fn remove_key_from_keys(&self, key: &Key) -> Result<usize, Error>;
// Provided method
fn is_info_hash_whitelisted(
&self,
info_hash: InfoHash,
) -> Result<bool, Error> { ... }
}Expand description
The persistence trait. It contains all the methods to interact with the database.
Required Methods§
Sourcefn new(db_path: &str) -> Result<Self, Error>where
Self: Sized,
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.
Sourcefn create_database_tables(&self) -> Result<(), Error>
fn create_database_tables(&self) -> Result<(), Error>
Sourcefn drop_database_tables(&self) -> Result<(), Error>
fn drop_database_tables(&self) -> Result<(), Error>
Sourcefn load_persistent_torrents(&self) -> Result<PersistentTorrents, Error>
fn load_persistent_torrents(&self) -> Result<PersistentTorrents, Error>
It loads the torrent metrics data from the database.
It returns an array of tuples with the torrent
InfoHash and the
downloaded counter
which is the number of times the torrent has been downloaded.
See Entry::downloaded.
§Context: Torrent Metrics
§Errors
Will return Err if unable to load.