formatting and adding video model
This commit is contained in:
parent
de34c6818a
commit
887fc733e7
8 changed files with 196 additions and 84 deletions
|
@ -1,15 +1,62 @@
|
|||
use color_eyre::eyre::Result;
|
||||
use sqlx::{Connection, SqliteConnection};
|
||||
|
||||
use crate::songs::Song;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Model<T> {
|
||||
pub items: Vec<T>,
|
||||
pub db: SqliteConnection,
|
||||
}
|
||||
|
||||
pub trait Models {
|
||||
// impl<T> Modeling for Model<T> {
|
||||
// type Item = T;
|
||||
// fn add_item(&mut self, item: Self::Item) -> Result<()> {
|
||||
// self.items.push(item);
|
||||
// Ok(())
|
||||
// }
|
||||
|
||||
// fn add_to_db(&mut self, item: Self::Item) -> Result<()> {
|
||||
// todo!()
|
||||
// }
|
||||
|
||||
// fn update_item(&mut self, item: Self::Item, index: i32) -> Result<()> {
|
||||
// todo!()
|
||||
// }
|
||||
|
||||
// fn remove_item(&mut self, index: i32) -> Result<()> {
|
||||
// todo!()
|
||||
// }
|
||||
|
||||
// fn get_item(&self, index: i32) -> Option<&Self::Item> {
|
||||
// todo!()
|
||||
// }
|
||||
|
||||
// fn insert_item(&mut self, item: Self::Item, index: i32) -> Result<()> {
|
||||
// todo!()
|
||||
// }
|
||||
// }
|
||||
|
||||
impl<T> Default for Model<T> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
items: vec![],
|
||||
db: {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
let mut data = dirs::data_local_dir().unwrap();
|
||||
data.push("lumina");
|
||||
data.push("library-db.sqlite3");
|
||||
let mut db_url = String::from("sqlite://");
|
||||
db_url.push_str(data.to_str().unwrap());
|
||||
rt.block_on(async {
|
||||
SqliteConnection::connect(&db_url)
|
||||
.await
|
||||
.expect("problems")
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Modeling {
|
||||
type Item;
|
||||
|
||||
fn setup_db() -> SqliteConnection {
|
||||
|
@ -20,15 +67,26 @@ pub trait Models {
|
|||
let mut db_url = String::from("sqlite://");
|
||||
db_url.push_str(data.to_str().unwrap());
|
||||
rt.block_on(async {
|
||||
SqliteConnection::connect(&db_url).await.expect("problems")
|
||||
SqliteConnection::connect(&db_url)
|
||||
.await
|
||||
.expect("problems")
|
||||
})
|
||||
}
|
||||
|
||||
fn add_item(&mut self, item: Self::Item) -> Result<()>;
|
||||
fn add_to_db(&mut self, item: Self::Item) -> Result<()>;
|
||||
fn update_item(&mut self, item: Self::Item, index: i32) -> Result<()>;
|
||||
fn update_item(
|
||||
&mut self,
|
||||
item: Self::Item,
|
||||
index: i32,
|
||||
) -> Result<()>;
|
||||
fn remove_item(&mut self, index: i32) -> Result<()>;
|
||||
fn get_item(&self, index: i32) -> Option<&Self::Item>;
|
||||
fn insert_item(
|
||||
&mut self,
|
||||
item: Self::Item,
|
||||
index: i32,
|
||||
) -> Result<()>;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue