some bare minimum trait work for songs
This commit is contained in:
parent
c8bb484a53
commit
de34c6818a
6 changed files with 236 additions and 26 deletions
37
src/rust/core/model.rs
Normal file
37
src/rust/core/model.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
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 {
|
||||
type Item;
|
||||
|
||||
fn setup_db() -> SqliteConnection {
|
||||
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")
|
||||
})
|
||||
}
|
||||
|
||||
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 remove_item(&mut self, index: i32) -> Result<()>;
|
||||
fn get_item(&self, index: i32) -> Option<&Self::Item>;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue