mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Keep playing random tracks after the playlist ends
This commit is contained in:
parent
42d1d047e3
commit
487fd0a048
3 changed files with 35 additions and 7 deletions
|
|
@ -49,7 +49,7 @@ struct MediumRow {
|
|||
}
|
||||
|
||||
/// Table data for a [`Track`].
|
||||
#[derive(Insertable, Queryable, Debug, Clone)]
|
||||
#[derive(Insertable, Queryable, QueryableByName, Debug, Clone)]
|
||||
#[table_name = "tracks"]
|
||||
struct TrackRow {
|
||||
pub id: String,
|
||||
|
|
@ -224,6 +224,17 @@ impl Database {
|
|||
Ok(tracks)
|
||||
}
|
||||
|
||||
/// Get a random track from the database.
|
||||
pub fn random_track(&self) -> Result<Track> {
|
||||
let row = diesel::sql_query("SELECT * FROM tracks ORDER BY RANDOM() LIMIT 1")
|
||||
.load::<TrackRow>(&self.connection)?
|
||||
.into_iter()
|
||||
.next()
|
||||
.ok_or(Error::Other("Failed to generate random track"))?;
|
||||
|
||||
self.get_track_from_row(row)
|
||||
}
|
||||
|
||||
/// Retrieve all available information on a medium from related tables.
|
||||
fn get_medium_data(&self, row: MediumRow) -> Result<Medium> {
|
||||
let track_rows = tracks::table
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue