Struct termusiclib::podcast::db::Database
source · pub struct Database { /* private fields */ }Expand description
Struct holding a sqlite database connection, with methods to interact with this connection.
Implementations§
source§impl Database
impl Database
sourcepub fn connect(path: &Path) -> Result<Database>
pub fn connect(path: &Path) -> Result<Database>
Creates a new connection to the database (and creates database if it does not already exist).
§Panics
if database cannot be accessed.
sourcepub fn create(&self) -> Result<()>
pub fn create(&self) -> Result<()>
Creates the necessary database tables, if they do not already exist. Panics if database cannot be accessed, or if tables cannot be created.
sourcepub fn insert_podcast(&self, podcast: &PodcastNoId) -> Result<SyncResult>
pub fn insert_podcast(&self, podcast: &PodcastNoId) -> Result<SyncResult>
Inserts a new podcast and list of podcast episodes into the database.
sourcepub fn insert_episode(
conn: &Connection,
podcast_id: i64,
episode: &EpisodeNoId
) -> Result<i64>
pub fn insert_episode( conn: &Connection, podcast_id: i64, episode: &EpisodeNoId ) -> Result<i64>
Inserts a podcast episode into the database.
sourcepub fn insert_file(&self, episode_id: i64, path: &Path) -> Result<()>
pub fn insert_file(&self, episode_id: i64, path: &Path) -> Result<()>
Inserts a filepath to a downloaded episode.
sourcepub fn remove_file(&self, episode_id: i64) -> Result<()>
pub fn remove_file(&self, episode_id: i64) -> Result<()>
Removes a file listing for an episode from the database when the user has chosen to delete the file.
sourcepub fn remove_files(&self, episode_ids: &[i64]) -> Result<()>
pub fn remove_files(&self, episode_ids: &[i64]) -> Result<()>
Removes all file listings for the selected episode ids.
sourcepub fn remove_podcast(&self, podcast_id: i64) -> Result<()>
pub fn remove_podcast(&self, podcast_id: i64) -> Result<()>
Removes a podcast, all episodes, and files from the database.
sourcepub fn update_podcast(
&self,
pod_id: i64,
podcast: &PodcastNoId
) -> Result<SyncResult>
pub fn update_podcast( &self, pod_id: i64, podcast: &PodcastNoId ) -> Result<SyncResult>
Updates an existing podcast in the database, where metadata is changed if necessary, and episodes are updated (modified episodes are updated, new episodes are inserted).
sourcepub fn set_played_status(&self, episode_id: i64, played: bool) -> Result<()>
pub fn set_played_status(&self, episode_id: i64, played: bool) -> Result<()>
Updates an episode to mark it as played or unplayed.
sourcepub fn set_all_played_status(
&self,
episode_id_vec: &[i64],
played: bool
) -> Result<()>
pub fn set_all_played_status( &self, episode_id_vec: &[i64], played: bool ) -> Result<()>
Updates an episode to mark it as played or unplayed.
sourcepub fn hide_episode(&self, episode_id: i64, hide: bool) -> Result<()>
pub fn hide_episode(&self, episode_id: i64, hide: bool) -> Result<()>
Updates an episode to “remove” it by hiding it. “Removed” episodes need to stay in the database so that they don’t get re-added when the podcast is synced again.
sourcepub fn get_podcasts(&self) -> Result<Vec<Podcast>>
pub fn get_podcasts(&self) -> Result<Vec<Podcast>>
Generates list of all podcasts in database. TODO: This should probably use a JOIN statement instead.
sourcepub fn get_episodes(
&self,
pod_id: i64,
include_hidden: bool
) -> Result<Vec<Episode>>
pub fn get_episodes( &self, pod_id: i64, include_hidden: bool ) -> Result<Vec<Episode>>
Generates list of episodes for a given podcast.
pub fn get_last_position(&mut self, track: &Track) -> Result<Duration>
sourcepub fn set_last_position(&mut self, track: &Track, last_position: Duration)
pub fn set_last_position(&mut self, track: &Track, last_position: Duration)
§Panics
if the connection is unavailable