tweaks to add sqlx
This commit is contained in:
parent
186142a012
commit
bfb723a413
3 changed files with 455 additions and 411 deletions
1
.envrc
1
.envrc
|
@ -4,6 +4,7 @@ export CMAKE_EXPORT_COMPILE_COMMANDS=1
|
||||||
export CMAKE_BUILD_TYPE=Debug
|
export CMAKE_BUILD_TYPE=Debug
|
||||||
export CXX=g++
|
export CXX=g++
|
||||||
export CC=gcc
|
export CC=gcc
|
||||||
|
export DATABASE_URL=sqlite:///home/chris/.local/share/lumina/library-db.sqlite3
|
||||||
# export CXXQT_INCLUDE_PATH=$GUIX_ENVIRONMENT/include
|
# export CXXQT_INCLUDE_PATH=$GUIX_ENVIRONMENT/include
|
||||||
# export INCLUDEPATH="/gnu/store/pkjvij1f6rvx42xv2kygicr7fsch41dl-profile/include"
|
# export INCLUDEPATH="/gnu/store/pkjvij1f6rvx42xv2kygicr7fsch41dl-profile/include"
|
||||||
use flake . --impure
|
use flake . --impure
|
||||||
|
|
|
@ -60,6 +60,7 @@ mkShell rec {
|
||||||
cargo
|
cargo
|
||||||
rustfmt
|
rustfmt
|
||||||
rust-analyzer
|
rust-analyzer
|
||||||
|
sqlx-cli
|
||||||
corrosion
|
corrosion
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -289,13 +289,41 @@ impl Default for Song {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SongModelRust {
|
pub struct SongModelRust<'a> {
|
||||||
count: i32,
|
count: i32,
|
||||||
highest_id: i32,
|
highest_id: i32,
|
||||||
songs: Vec<Song>,
|
songs: Vec<Song>,
|
||||||
inner_songs: Vec<Song>,
|
inner_songs: Vec<Song>,
|
||||||
db: SqliteConnection,
|
db: Option<&'a SqliteConnection>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for SongModelRust<'a> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
count: 0,
|
||||||
|
highest_id: 0,
|
||||||
|
songs: vec![],
|
||||||
|
inner_songs: 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 {
|
||||||
|
match SqliteConnection::connect(&db_url).await {
|
||||||
|
Ok(db) => Some(&db),
|
||||||
|
Err(e) => {
|
||||||
|
error!("Error connecting to db: {e}");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl song_model::SongModel {
|
impl song_model::SongModel {
|
||||||
|
@ -315,102 +343,50 @@ impl song_model::SongModel {
|
||||||
let mut db_url = String::from("sqlite://");
|
let mut db_url = String::from("sqlite://");
|
||||||
db_url.push_str(data.to_str().unwrap());
|
db_url.push_str(data.to_str().unwrap());
|
||||||
println!("DB: {:?}", db_url);
|
println!("DB: {:?}", db_url);
|
||||||
|
|
||||||
static DATABASE_URL: &str = "sqlite:///home/chris/.local/share/lumina/library-db.sqlite3";
|
static DATABASE_URL: &str = "sqlite:///home/chris/.local/share/lumina/library-db.sqlite3";
|
||||||
let thread = self.qt_thread();
|
let thread = self.qt_thread();
|
||||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
rt.block_on(async {
|
rt.block_on(async {
|
||||||
match SqliteConnection::connect(&db_url).await {
|
let result = query_as!(Song, r#"SELECT vorder as "verse_order!", fontSize as "font_size!: i32", backgroundType as "background_type!", horizontalTextAlignment as "horizontal_text_alignment!", verticalTextAlignment as "vertical_text_alignment!", title as "title!", font as "font!", background as "background!", lyrics as "lyrics!", ccli as "ccli!", author as "author!", audio as "audio!", id as "id: i32" from songs"#).fetch_all(&mut self.as_mut().rust_mut().db.unwrap()).await;
|
||||||
Ok(db) => {
|
|
||||||
thread.queue(|s| s.as_mut().rust_mut().db = db);
|
|
||||||
let result = query_as!(Song, r#"SELECT vorder as "verse_order!", fontSize as "font_size!: i32", backgroundType as "background_type!", horizontalTextAlignment as "horizontal_text_alignment!", verticalTextAlignment as "vertical_text_alignment!", title as "title!", font as "font!", background as "background!", lyrics as "lyrics!", ccli as "ccli!", author as "author!", audio as "audio!", id as "id: i32" from songs"#).fetch_all(&mut self.as_mut().rust_mut().db).await;
|
|
||||||
match result {
|
match result {
|
||||||
Ok(s) => s.into_iter().for_each(|s| self.as_mut().add_song(s)),
|
Ok(s) => s.into_iter().for_each(|s| self.as_mut().add_song(s)),
|
||||||
Err(e) => error!("There was an error in converting songs: {e}"),
|
Err(e) => error!("There was an error in converting songs: {e}"),
|
||||||
}
|
}
|
||||||
},
|
|
||||||
Err(e) => error!("There was an error in the db: {e}"),
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// run_migrations(db);
|
|
||||||
// let results = songs
|
|
||||||
// .load::<crate::models::Song>(db)
|
|
||||||
// .expect("NO TABLE?????????????");
|
|
||||||
// self.as_mut().rust_mut().highest_id = 0;
|
|
||||||
|
|
||||||
// println!("SHOWING SONGS");
|
|
||||||
// println!("--------------");
|
|
||||||
// for song in results {
|
|
||||||
// println!("{}", song.title);
|
|
||||||
// println!("{}", song.id);
|
|
||||||
// println!(
|
|
||||||
// "{}",
|
|
||||||
// song.background.clone().unwrap_or_default()
|
|
||||||
// );
|
|
||||||
// println!("--------------");
|
|
||||||
// if self.as_mut().highest_id < song.id {
|
|
||||||
// self.as_mut().rust_mut().highest_id = song.id;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let song = Song {
|
|
||||||
// id: song.id,
|
|
||||||
// title: song.title,
|
|
||||||
// lyrics: song.lyrics.unwrap_or_default(),
|
|
||||||
// author: song.author.unwrap_or_default(),
|
|
||||||
// ccli: song.ccli.unwrap_or_default(),
|
|
||||||
// audio: song.audio.unwrap_or_default(),
|
|
||||||
// verse_order: song.verse_order.unwrap_or_default(),
|
|
||||||
// background: song.background.unwrap_or_default(),
|
|
||||||
// background_type: song
|
|
||||||
// .background_type
|
|
||||||
// .unwrap_or_default(),
|
|
||||||
// horizontal_text_alignment: song
|
|
||||||
// .horizontal_text_alignment
|
|
||||||
// .unwrap_or_default(),
|
|
||||||
// vertical_text_alignment: song
|
|
||||||
// .vertical_text_alignment
|
|
||||||
// .unwrap_or_default(),
|
|
||||||
// font: song.font.unwrap_or_default(),
|
|
||||||
// font_size: song.font_size.unwrap_or_default(),
|
|
||||||
// };
|
|
||||||
|
|
||||||
// self.as_mut().add_song(song);
|
|
||||||
// }
|
|
||||||
// println!("--------------------------------------");
|
|
||||||
// println!("{:?}", self.as_mut().songs);
|
|
||||||
// println!("--------------------------------------");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) -> bool {
|
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) -> bool {
|
||||||
if index < 0 || (index as usize) >= self.songs.len() {
|
if index < 0 || (index as usize) >= self.songs.len() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let db = &mut self.as_mut().rust_mut().db;
|
|
||||||
|
|
||||||
let song_id = self.songs.get(index as usize).unwrap().id;
|
let song_id = self.as_mut().rust_mut().songs.get(index as usize).unwrap().id;
|
||||||
|
let thread = self.qt_thread();
|
||||||
|
let db = &mut self.as_mut().rust_mut().db.unwrap();
|
||||||
|
|
||||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
rt.block_on(async {
|
rt.block_on(async {
|
||||||
let result = query!("delete from songs where id = ?", song_id).fetch_optional(db).await;
|
let result = query!("delete from songs where id = ?", song_id).fetch_optional(db).await;
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
thread.queue(move |mut song_model| {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.as_mut().begin_remove_rows(
|
song_model.as_mut().begin_remove_rows(
|
||||||
&QModelIndex::default(),
|
&QModelIndex::default(),
|
||||||
index,
|
index,
|
||||||
index,
|
index,
|
||||||
);
|
);
|
||||||
self.as_mut()
|
song_model.as_mut()
|
||||||
.rust_mut()
|
.rust_mut()
|
||||||
.songs
|
.songs
|
||||||
.remove(index as usize);
|
.remove(index as usize);
|
||||||
self.as_mut()
|
song_model.as_mut()
|
||||||
.rust_mut()
|
.rust_mut()
|
||||||
.inner_songs
|
.inner_songs
|
||||||
.remove(index as usize);
|
.remove(index as usize);
|
||||||
self.as_mut().end_remove_rows();
|
song_model.as_mut().end_remove_rows();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
debug!("removed-item-at-index: {:?}", song_id);
|
debug!("removed-item-at-index: {:?}", song_id);
|
||||||
true
|
true
|
||||||
},
|
},
|
||||||
|
@ -430,7 +406,7 @@ impl song_model::SongModel {
|
||||||
pub fn new_song(mut self: Pin<&mut Self>) -> bool {
|
pub fn new_song(mut self: Pin<&mut Self>) -> bool {
|
||||||
let song_id = self.rust().highest_id + 1;
|
let song_id = self.rust().highest_id + 1;
|
||||||
let song_title = String::from("title");
|
let song_title = String::from("title");
|
||||||
let db = &mut self.as_mut().get_db();
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
|
|
||||||
let song = Song {
|
let song = Song {
|
||||||
id: song_id,
|
id: song_id,
|
||||||
|
@ -438,26 +414,8 @@ impl song_model::SongModel {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = insert_into(songs)
|
rt.block_on(async {
|
||||||
.values((
|
let result = query!(r#"INSERT into songs (vorder, fontSize, backgroundType, horizontalTextAlignment, verticalTextAlignment, title, font, background, lyrics, ccli, author, audio, id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"#, song.verse_order, song.font_size, song.background_type, song.horizontal_text_alignment, song.vertical_text_alignment, song.title, song.font, song.background, song.lyrics, song.ccli, song.author, song.audio, song.id).fetch_all(&mut self.as_mut().rust_mut().db.unwrap()).await;
|
||||||
id.eq(&song_id),
|
|
||||||
title.eq(&song_title),
|
|
||||||
lyrics.eq(&song.lyrics),
|
|
||||||
author.eq(&song.author),
|
|
||||||
ccli.eq(&song.ccli),
|
|
||||||
audio.eq(&song.audio),
|
|
||||||
verse_order.eq(&song.verse_order),
|
|
||||||
background.eq(&song.background),
|
|
||||||
background_type.eq(&song.background_type),
|
|
||||||
horizontal_text_alignment
|
|
||||||
.eq(&song.horizontal_text_alignment),
|
|
||||||
vertical_text_alignment
|
|
||||||
.eq(&song.vertical_text_alignment),
|
|
||||||
font.eq(&song.font),
|
|
||||||
font_size.eq(&song.font_size),
|
|
||||||
))
|
|
||||||
.execute(db);
|
|
||||||
println!("{:?}", result);
|
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
|
@ -470,6 +428,8 @@ impl song_model::SongModel {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_song(mut self: Pin<&mut Self>, song: self::Song) {
|
fn add_song(mut self: Pin<&mut Self>, song: self::Song) {
|
||||||
|
@ -520,13 +480,15 @@ impl song_model::SongModel {
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let (index, model_index, vector_roles) =
|
let (index, model_index, vector_roles) =
|
||||||
self.as_mut().get_indices(song_id, SongRoles::Title);
|
self.as_mut().get_indices(song_id, SongRoles::Title);
|
||||||
let db = &mut self.as_mut().get_db();
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
let result = update(songs.filter(id.eq(song_id)))
|
let db_string = updated_title.clone().to_string();
|
||||||
.set(title.eq(updated_title.to_string()))
|
rt.block_on(async {
|
||||||
.execute(db);
|
let result = query!("UPDATE songs SET title = ?", db_string)
|
||||||
|
.execute(&mut self.as_mut().rust_mut().db.unwrap())
|
||||||
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
debug!(_i, index);
|
|
||||||
if let Some(song) =
|
if let Some(song) =
|
||||||
self.as_mut().rust_mut().songs.get_mut(index)
|
self.as_mut().rust_mut().songs.get_mut(index)
|
||||||
{
|
{
|
||||||
|
@ -542,8 +504,13 @@ impl song_model::SongModel {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_e) => false,
|
Err(e) => {
|
||||||
|
error!("There was an error updating title in db: {e}");
|
||||||
|
false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_lyrics(
|
pub fn update_lyrics(
|
||||||
|
@ -553,10 +520,13 @@ impl song_model::SongModel {
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let (index, model_index, vector_roles) =
|
let (index, model_index, vector_roles) =
|
||||||
self.as_mut().get_indices(song_id, SongRoles::Lyrics);
|
self.as_mut().get_indices(song_id, SongRoles::Lyrics);
|
||||||
let db = &mut self.as_mut().get_db();
|
let db_string = updated_lyrics.clone().to_string();
|
||||||
let result = update(songs.filter(id.eq(song_id)))
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
.set(lyrics.eq(updated_lyrics.to_string()))
|
rt.block_on(async {
|
||||||
.execute(db);
|
let result = query!("UPDATE songs SET lyrics = ?", db_string)
|
||||||
|
.execute(&mut self.as_mut().rust_mut().db.unwrap())
|
||||||
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) =
|
if let Some(song) =
|
||||||
|
@ -577,8 +547,13 @@ impl song_model::SongModel {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_e) => false,
|
Err(e) => {
|
||||||
|
error!("There was an error updating lyrics in db: {e}");
|
||||||
|
false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_author(
|
pub fn update_author(
|
||||||
|
@ -589,10 +564,13 @@ impl song_model::SongModel {
|
||||||
let (index, model_index, vector_roles) =
|
let (index, model_index, vector_roles) =
|
||||||
self.as_mut().get_indices(song_id, SongRoles::Author);
|
self.as_mut().get_indices(song_id, SongRoles::Author);
|
||||||
|
|
||||||
let db = &mut self.as_mut().get_db();
|
let db_string = updated_author.clone().to_string();
|
||||||
let result = update(songs.filter(id.eq(song_id)))
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
.set(author.eq(updated_author.to_string()))
|
rt.block_on(async {
|
||||||
.execute(db);
|
let result = query!("UPDATE songs SET author = ?", db_string)
|
||||||
|
.execute(&mut self.as_mut().rust_mut().db.unwrap())
|
||||||
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) =
|
if let Some(song) =
|
||||||
|
@ -613,8 +591,13 @@ impl song_model::SongModel {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_e) => false,
|
Err(e) => {
|
||||||
|
error!("There was an error updating author in db: {e}");
|
||||||
|
false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_audio(
|
pub fn update_audio(
|
||||||
|
@ -625,20 +608,23 @@ impl song_model::SongModel {
|
||||||
let (index, model_index, vector_roles) =
|
let (index, model_index, vector_roles) =
|
||||||
self.as_mut().get_indices(song_id, SongRoles::Audio);
|
self.as_mut().get_indices(song_id, SongRoles::Audio);
|
||||||
|
|
||||||
debug!(?updated_audio);
|
let db_string = updated_audio.clone().to_string();
|
||||||
let db = &mut self.as_mut().get_db();
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
let result = update(songs.filter(id.eq(song_id)))
|
rt.block_on(async {
|
||||||
.set(audio.eq(updated_audio.to_string()))
|
let result = query!("UPDATE songs SET audio = ?", db_string)
|
||||||
.execute(db);
|
.execute(&mut self.as_mut().rust_mut().db.unwrap())
|
||||||
debug!(?result);
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) =
|
if let Some(song) =
|
||||||
self.as_mut().rust_mut().songs.get_mut(index)
|
self.as_mut().rust_mut().songs.get_mut(index)
|
||||||
{
|
{
|
||||||
debug!(?song, audio = updated_audio.to_string());
|
debug!(
|
||||||
|
?song,
|
||||||
|
audio = updated_audio.to_string()
|
||||||
|
);
|
||||||
song.audio = updated_audio.to_string();
|
song.audio = updated_audio.to_string();
|
||||||
debug!(?song);
|
|
||||||
self.as_mut().data_changed(
|
self.as_mut().data_changed(
|
||||||
&model_index,
|
&model_index,
|
||||||
&model_index,
|
&model_index,
|
||||||
|
@ -649,8 +635,13 @@ impl song_model::SongModel {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_e) => false,
|
Err(e) => {
|
||||||
|
error!("There was an error updating audio in db: {e}");
|
||||||
|
false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_ccli(
|
pub fn update_ccli(
|
||||||
|
@ -661,16 +652,22 @@ impl song_model::SongModel {
|
||||||
let (index, model_index, vector_roles) =
|
let (index, model_index, vector_roles) =
|
||||||
self.as_mut().get_indices(song_id, SongRoles::Ccli);
|
self.as_mut().get_indices(song_id, SongRoles::Ccli);
|
||||||
|
|
||||||
let db = &mut self.as_mut().get_db();
|
let db_string = updated_ccli.clone().to_string();
|
||||||
let result = update(songs.filter(id.eq(song_id)))
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
.set(ccli.eq(updated_ccli.to_string()))
|
rt.block_on(async {
|
||||||
.execute(db);
|
let result = query!("UPDATE songs SET ccli = ?", db_string)
|
||||||
|
.execute(&mut self.as_mut().rust_mut().db.unwrap())
|
||||||
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) =
|
if let Some(song) =
|
||||||
self.as_mut().rust_mut().songs.get_mut(index)
|
self.as_mut().rust_mut().songs.get_mut(index)
|
||||||
{
|
{
|
||||||
debug!(?song, ccli = updated_ccli.to_string());
|
debug!(
|
||||||
|
?song,
|
||||||
|
ccli = updated_ccli.to_string()
|
||||||
|
);
|
||||||
song.ccli = updated_ccli.to_string();
|
song.ccli = updated_ccli.to_string();
|
||||||
self.as_mut().data_changed(
|
self.as_mut().data_changed(
|
||||||
&model_index,
|
&model_index,
|
||||||
|
@ -682,8 +679,13 @@ impl song_model::SongModel {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_e) => false,
|
Err(e) => {
|
||||||
|
error!("There was an error updating ccli in db: {e}");
|
||||||
|
false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_verse_order(
|
pub fn update_verse_order(
|
||||||
|
@ -694,10 +696,13 @@ impl song_model::SongModel {
|
||||||
let (index, model_index, vector_roles) =
|
let (index, model_index, vector_roles) =
|
||||||
self.as_mut().get_indices(song_id, SongRoles::VerseOrder);
|
self.as_mut().get_indices(song_id, SongRoles::VerseOrder);
|
||||||
|
|
||||||
let db = &mut self.as_mut().get_db();
|
let db_string = updated_verse_order.clone().to_string();
|
||||||
let result = update(songs.filter(id.eq(song_id)))
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
.set(verse_order.eq(updated_verse_order.to_string()))
|
rt.block_on(async {
|
||||||
.execute(db);
|
let result = query!("UPDATE songs SET vorder = ?", db_string)
|
||||||
|
.execute(&mut self.as_mut().rust_mut().db.unwrap())
|
||||||
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) =
|
if let Some(song) =
|
||||||
|
@ -707,8 +712,7 @@ impl song_model::SongModel {
|
||||||
?song,
|
?song,
|
||||||
verse_order = updated_verse_order.to_string()
|
verse_order = updated_verse_order.to_string()
|
||||||
);
|
);
|
||||||
song.verse_order =
|
song.verse_order = updated_verse_order.to_string();
|
||||||
updated_verse_order.to_string();
|
|
||||||
self.as_mut().data_changed(
|
self.as_mut().data_changed(
|
||||||
&model_index,
|
&model_index,
|
||||||
&model_index,
|
&model_index,
|
||||||
|
@ -719,8 +723,13 @@ impl song_model::SongModel {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_e) => false,
|
Err(e) => {
|
||||||
|
error!("There was an error updating verse_order in db: {e}");
|
||||||
|
false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_background(
|
pub fn update_background(
|
||||||
|
@ -731,34 +740,40 @@ impl song_model::SongModel {
|
||||||
let (index, model_index, vector_roles) =
|
let (index, model_index, vector_roles) =
|
||||||
self.as_mut().get_indices(song_id, SongRoles::Background);
|
self.as_mut().get_indices(song_id, SongRoles::Background);
|
||||||
|
|
||||||
let db = &mut self.as_mut().get_db();
|
let db_string = updated_background.clone().to_string();
|
||||||
let result = update(songs.filter(id.eq(song_id)))
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
.set(background.eq(updated_background.to_string()))
|
rt.block_on(async {
|
||||||
.execute(db);
|
let result = query!("UPDATE songs SET background = ?", db_string)
|
||||||
|
.execute(&mut self.as_mut().rust_mut().db.unwrap())
|
||||||
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) =
|
if let Some(song) =
|
||||||
self.as_mut().rust_mut().songs.get_mut(index)
|
self.as_mut().rust_mut().songs.get_mut(index)
|
||||||
{
|
{
|
||||||
song.background = updated_background.to_string();
|
|
||||||
debug!(
|
debug!(
|
||||||
background = ?updated_background,
|
?song,
|
||||||
model_index = ?model_index,
|
background = updated_background.to_string()
|
||||||
roles = vector_roles.get(0)
|
|
||||||
);
|
);
|
||||||
|
song.background = updated_background.to_string();
|
||||||
self.as_mut().data_changed(
|
self.as_mut().data_changed(
|
||||||
&model_index,
|
&model_index,
|
||||||
&model_index,
|
&model_index,
|
||||||
&vector_roles,
|
&vector_roles,
|
||||||
);
|
);
|
||||||
self.as_mut().background_changed();
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_e) => false,
|
Err(e) => {
|
||||||
|
error!("There was an error updating background in db: {e}");
|
||||||
|
false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_background_type(
|
pub fn update_background_type(
|
||||||
|
@ -770,13 +785,13 @@ impl song_model::SongModel {
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.get_indices(song_id, SongRoles::BackgroundType);
|
.get_indices(song_id, SongRoles::BackgroundType);
|
||||||
|
|
||||||
let db = &mut self.as_mut().get_db();
|
let db_string = updated_background_type.clone().to_string();
|
||||||
let result = update(songs.filter(id.eq(song_id)))
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
.set(
|
rt.block_on(async {
|
||||||
background_type
|
let result = query!("UPDATE songs SET backgroundType = ?", db_string)
|
||||||
.eq(updated_background_type.to_string()),
|
.execute(&mut self.as_mut().rust_mut().db.unwrap())
|
||||||
)
|
.await;
|
||||||
.execute(db);
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) =
|
if let Some(song) =
|
||||||
|
@ -784,11 +799,9 @@ impl song_model::SongModel {
|
||||||
{
|
{
|
||||||
debug!(
|
debug!(
|
||||||
?song,
|
?song,
|
||||||
background_type =
|
background_type = updated_background_type.to_string()
|
||||||
updated_background_type.to_string()
|
|
||||||
);
|
);
|
||||||
song.background_type =
|
song.background_type = updated_background_type.to_string();
|
||||||
updated_background_type.to_string();
|
|
||||||
self.as_mut().data_changed(
|
self.as_mut().data_changed(
|
||||||
&model_index,
|
&model_index,
|
||||||
&model_index,
|
&model_index,
|
||||||
|
@ -799,8 +812,13 @@ impl song_model::SongModel {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_e) => false,
|
Err(e) => {
|
||||||
|
error!("There was an error updating background_type in db: {e}");
|
||||||
|
false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_horizontal_text_alignment(
|
pub fn update_horizontal_text_alignment(
|
||||||
|
@ -812,13 +830,13 @@ impl song_model::SongModel {
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.get_indices(song_id, SongRoles::HorizontalTextAlignment);
|
.get_indices(song_id, SongRoles::HorizontalTextAlignment);
|
||||||
|
|
||||||
let db = &mut self.as_mut().get_db();
|
let db_string = updated_horizontal_text_alignment.clone().to_string();
|
||||||
let result =
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
update(songs.filter(id.eq(song_id)))
|
rt.block_on(async {
|
||||||
.set(horizontal_text_alignment.eq(
|
let result = query!("UPDATE songs SET horizontalTextAlignment = ?", db_string)
|
||||||
updated_horizontal_text_alignment.to_string(),
|
.execute(&mut self.as_mut().rust_mut().db.unwrap())
|
||||||
))
|
.await;
|
||||||
.execute(db);
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) =
|
if let Some(song) =
|
||||||
|
@ -826,12 +844,9 @@ impl song_model::SongModel {
|
||||||
{
|
{
|
||||||
debug!(
|
debug!(
|
||||||
?song,
|
?song,
|
||||||
horizontal =
|
horizontal_text_alignment = updated_horizontal_text_alignment.to_string()
|
||||||
updated_horizontal_text_alignment
|
|
||||||
.to_string()
|
|
||||||
);
|
);
|
||||||
song.horizontal_text_alignment =
|
song.horizontal_text_alignment = updated_horizontal_text_alignment.to_string();
|
||||||
updated_horizontal_text_alignment.to_string();
|
|
||||||
self.as_mut().data_changed(
|
self.as_mut().data_changed(
|
||||||
&model_index,
|
&model_index,
|
||||||
&model_index,
|
&model_index,
|
||||||
|
@ -842,8 +857,13 @@ impl song_model::SongModel {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_e) => false,
|
Err(e) => {
|
||||||
|
error!("There was an error updating horizontal_text_alignment in db: {e}");
|
||||||
|
false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_vertical_text_alignment(
|
pub fn update_vertical_text_alignment(
|
||||||
|
@ -855,13 +875,13 @@ impl song_model::SongModel {
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.get_indices(song_id, SongRoles::VerticalTextAlignment);
|
.get_indices(song_id, SongRoles::VerticalTextAlignment);
|
||||||
|
|
||||||
let db = &mut self.as_mut().get_db();
|
let db_string = updated_vertical_text_alignment.clone().to_string();
|
||||||
let result = update(songs.filter(id.eq(song_id)))
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
.set(
|
rt.block_on(async {
|
||||||
vertical_text_alignment
|
let result = query!("UPDATE songs SET verticalTextAlignment = ?", db_string)
|
||||||
.eq(updated_vertical_text_alignment.to_string()),
|
.execute(&mut self.as_mut().rust_mut().db.unwrap())
|
||||||
)
|
.await;
|
||||||
.execute(db);
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) =
|
if let Some(song) =
|
||||||
|
@ -869,11 +889,9 @@ impl song_model::SongModel {
|
||||||
{
|
{
|
||||||
debug!(
|
debug!(
|
||||||
?song,
|
?song,
|
||||||
vertical = updated_vertical_text_alignment
|
vertical_text_alignment = updated_vertical_text_alignment.to_string()
|
||||||
.to_string()
|
|
||||||
);
|
);
|
||||||
song.vertical_text_alignment =
|
song.vertical_text_alignment = updated_vertical_text_alignment.to_string();
|
||||||
updated_vertical_text_alignment.to_string();
|
|
||||||
self.as_mut().data_changed(
|
self.as_mut().data_changed(
|
||||||
&model_index,
|
&model_index,
|
||||||
&model_index,
|
&model_index,
|
||||||
|
@ -884,8 +902,13 @@ impl song_model::SongModel {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_e) => false,
|
Err(e) => {
|
||||||
|
error!("There was an error updating vertical_text_alignment in db: {e}");
|
||||||
|
false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_font(
|
pub fn update_font(
|
||||||
|
@ -896,17 +919,23 @@ impl song_model::SongModel {
|
||||||
let (index, model_index, vector_roles) =
|
let (index, model_index, vector_roles) =
|
||||||
self.as_mut().get_indices(song_id, SongRoles::Font);
|
self.as_mut().get_indices(song_id, SongRoles::Font);
|
||||||
|
|
||||||
let db = &mut self.as_mut().get_db();
|
let db_string = updated_font.clone().to_string();
|
||||||
let result = update(songs.filter(id.eq(song_id)))
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
.set(font.eq(updated_font.to_string()))
|
rt.block_on(async {
|
||||||
.execute(db);
|
let result = query!("UPDATE songs SET font = ?", db_string)
|
||||||
|
.execute(&mut self.as_mut().rust_mut().db.unwrap())
|
||||||
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) =
|
if let Some(song) =
|
||||||
self.as_mut().rust_mut().songs.get_mut(index)
|
self.as_mut().rust_mut().songs.get_mut(index)
|
||||||
{
|
{
|
||||||
|
debug!(
|
||||||
|
?song,
|
||||||
|
font = updated_font.to_string()
|
||||||
|
);
|
||||||
song.font = updated_font.to_string();
|
song.font = updated_font.to_string();
|
||||||
debug!(?song, font = updated_font.to_string());
|
|
||||||
self.as_mut().data_changed(
|
self.as_mut().data_changed(
|
||||||
&model_index,
|
&model_index,
|
||||||
&model_index,
|
&model_index,
|
||||||
|
@ -917,8 +946,13 @@ impl song_model::SongModel {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_e) => false,
|
Err(e) => {
|
||||||
|
error!("There was an error updating font in db: {e}");
|
||||||
|
false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_font_size(
|
pub fn update_font_size(
|
||||||
|
@ -929,10 +963,13 @@ impl song_model::SongModel {
|
||||||
let (index, model_index, vector_roles) =
|
let (index, model_index, vector_roles) =
|
||||||
self.as_mut().get_indices(song_id, SongRoles::FontSize);
|
self.as_mut().get_indices(song_id, SongRoles::FontSize);
|
||||||
|
|
||||||
let db = &mut self.as_mut().get_db();
|
let db_string = updated_font_size.clone().to_string();
|
||||||
let result = update(songs.filter(id.eq(song_id)))
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
.set(font_size.eq(updated_font_size))
|
rt.block_on(async {
|
||||||
.execute(db);
|
let result = query!("UPDATE songs SET fontSize = ?", db_string)
|
||||||
|
.execute(&mut self.as_mut().rust_mut().db.unwrap())
|
||||||
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_i) => {
|
Ok(_i) => {
|
||||||
if let Some(song) =
|
if let Some(song) =
|
||||||
|
@ -940,7 +977,7 @@ impl song_model::SongModel {
|
||||||
{
|
{
|
||||||
debug!(
|
debug!(
|
||||||
?song,
|
?song,
|
||||||
font_size = updated_font_size.to_string()
|
font_size = updated_font_size
|
||||||
);
|
);
|
||||||
song.font_size = updated_font_size;
|
song.font_size = updated_font_size;
|
||||||
self.as_mut().data_changed(
|
self.as_mut().data_changed(
|
||||||
|
@ -953,8 +990,13 @@ impl song_model::SongModel {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_e) => false,
|
Err(e) => {
|
||||||
|
error!("There was an error updating font_size in db: {e}");
|
||||||
|
false
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_item(&self, index: i32) -> QMap_QString_QVariant {
|
pub fn get_item(&self, index: i32) -> QMap_QString_QVariant {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue