adding a lot more funcitonality to core library
This commit is contained in:
parent
ba51c56169
commit
3c87385895
7 changed files with 378 additions and 105 deletions
|
@ -1,10 +1,12 @@
|
|||
use crate::model::Model;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::query_as;
|
||||
use tracing::error;
|
||||
use std::path::PathBuf;
|
||||
use tracing::error;
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Video {
|
||||
pub id: i32,
|
||||
pub title: String,
|
||||
pub path: PathBuf,
|
||||
pub start_time: Option<f32>,
|
||||
|
@ -16,20 +18,19 @@ impl Model<Video> {
|
|||
pub fn load_from_db(&mut self) {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let result = query_as!(Video, r#"SELECT title as "title!", filePath as "path!", startTime as "start_time!: f32", endTime as "end_time!: f32", loop as "looping!" from videos"#).fetch_all(&mut self.db).await;
|
||||
let result = query_as!(Video, r#"SELECT title as "title!", filePath as "path!", startTime as "start_time!: f32", endTime as "end_time!: f32", loop as "looping!", id as "id: i32" from videos"#).fetch_all(&mut self.db).await;
|
||||
match result {
|
||||
Ok(v) => {
|
||||
for video in v.into_iter() {
|
||||
let _ = self.add_item(video);
|
||||
}
|
||||
}
|
||||
Err(e) => error!("There was an error in converting songs: {e}"),
|
||||
Err(e) => error!("There was an error in converting videos: {e}"),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
@ -64,9 +65,16 @@ mod test {
|
|||
match result {
|
||||
Ok(_) => {
|
||||
assert_eq!(&video, video_model.get_item(0).unwrap());
|
||||
assert_ne!(&new_video, video_model.get_item(0).unwrap());
|
||||
assert_ne!(
|
||||
&new_video,
|
||||
video_model.get_item(0).unwrap()
|
||||
);
|
||||
}
|
||||
Err(e) => assert!(false, "There was an error adding the video: {:?}", e),
|
||||
Err(e) => assert!(
|
||||
false,
|
||||
"There was an error adding the video: {:?}",
|
||||
e
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue