mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Add user preferences for random playback
This commit is contained in:
parent
3ae5727f39
commit
5c64bdef7e
14 changed files with 402 additions and 156 deletions
|
|
@ -76,7 +76,7 @@ impl PersonOrEnsemble {
|
|||
}
|
||||
|
||||
/// Database table data for a recording.
|
||||
#[derive(Insertable, Queryable, Debug, Clone)]
|
||||
#[derive(Insertable, Queryable, QueryableByName, Debug, Clone)]
|
||||
#[table_name = "recordings"]
|
||||
struct RecordingRow {
|
||||
pub id: String,
|
||||
|
|
@ -201,6 +201,17 @@ impl Database {
|
|||
Ok(recording)
|
||||
}
|
||||
|
||||
/// Get a random recording from the database.
|
||||
pub fn random_recording(&self) -> Result<Recording> {
|
||||
let row = diesel::sql_query("SELECT * FROM recordings ORDER BY RANDOM() LIMIT 1")
|
||||
.load::<RecordingRow>(&self.connection)?
|
||||
.into_iter()
|
||||
.next()
|
||||
.ok_or(Error::Other("Failed to find random recording."))?;
|
||||
|
||||
self.get_recording_data(row)
|
||||
}
|
||||
|
||||
/// Retrieve all available information on a recording from related tables.
|
||||
fn get_recording_data(&self, row: RecordingRow) -> Result<Recording> {
|
||||
let mut performance_descriptions: Vec<Performance> = Vec::new();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue