fixing lots of bugs
This commit is contained in:
parent
da735aa00b
commit
0ba3e7588b
24 changed files with 781 additions and 486 deletions
|
@ -181,7 +181,7 @@ pub struct ImageModelRust {
|
|||
highest_id: i32,
|
||||
images: Vec<Image>,
|
||||
inner_images: Vec<Image>,
|
||||
db: SqliteConnection
|
||||
db: SqliteConnection,
|
||||
}
|
||||
|
||||
impl Default for ImageModelRust {
|
||||
|
@ -199,9 +199,11 @@ impl Default for ImageModelRust {
|
|||
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")
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -215,11 +217,13 @@ pub fn get_image(index: i32) -> color_eyre::Result<Image> {
|
|||
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")
|
||||
})
|
||||
};
|
||||
rt.block_on(async {
|
||||
let result = query_as!(Image, r#"SELECT id as "id: i32", title as "title!", filePath as "path!" from images where id = ?"#, index).fetch_one(&mut db).await?;
|
||||
let result = query_as!(Image, r#"SELECT id as "id: i32", title as "title!", file_path as "path!" from images where id = ?"#, index).fetch_one(&mut db).await?;
|
||||
Ok(result)
|
||||
})
|
||||
}
|
||||
|
@ -236,7 +240,7 @@ impl image_model::ImageModel {
|
|||
pub fn setup(mut self: Pin<&mut Self>) {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let result = query_as!(Image, r#"SELECT id as "id: i32", title as "title!", filePath as "path!" from images"#).fetch_all(&mut self.as_mut().rust_mut().db).await;
|
||||
let result = query_as!(Image, r#"SELECT id as "id: i32", title as "title!", file_path as "path!" from images"#).fetch_all(&mut self.as_mut().rust_mut().db).await;
|
||||
match result {
|
||||
Ok(i) => i.into_iter().for_each(|i| self.as_mut().add_image(i)),
|
||||
Err(e) => error!("There was an error in converting songs: {e}"),
|
||||
|
@ -251,7 +255,10 @@ impl image_model::ImageModel {
|
|||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
|
||||
rt.block_on(async {
|
||||
let result = query!("delete from images where id = ?", index).execute(&mut self.as_mut().rust_mut().db).await;
|
||||
let result =
|
||||
query!("delete from images where id = ?", index)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_i) => {
|
||||
unsafe {
|
||||
|
@ -308,7 +315,7 @@ impl image_model::ImageModel {
|
|||
rt.block_on(async {
|
||||
let image_title = image_title.to_string();
|
||||
let image_path = image_path.to_string();
|
||||
let result = query!(r#"INSERT into images (id, title, filePath) VALUES (?, ?, ?)"#,
|
||||
let result = query!(r#"INSERT into images (id, title, file_path) VALUES (?, ?, ?)"#,
|
||||
image_id,
|
||||
image_title,
|
||||
image_path)
|
||||
|
@ -367,9 +374,13 @@ impl image_model::ImageModel {
|
|||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let title = updated_title.to_string();
|
||||
let result = query!("UPDATE images SET title = ? where id = ?", title, index)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
let result = query!(
|
||||
"UPDATE images SET title = ? where id = ?",
|
||||
title,
|
||||
index
|
||||
)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_i) => {
|
||||
for image in self
|
||||
|
@ -380,9 +391,11 @@ impl image_model::ImageModel {
|
|||
.filter(|x| x.id == index)
|
||||
{
|
||||
image.title = title.clone();
|
||||
debug!(title = image.title,
|
||||
title = title,
|
||||
"updated image title");
|
||||
debug!(
|
||||
title = image.title,
|
||||
title = title,
|
||||
"updated image title"
|
||||
);
|
||||
}
|
||||
self.as_mut().data_changed(
|
||||
model_index,
|
||||
|
@ -394,7 +407,7 @@ impl image_model::ImageModel {
|
|||
Err(e) => {
|
||||
error!("Error connecting to db: {e}");
|
||||
false
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
true
|
||||
|
@ -414,9 +427,13 @@ impl image_model::ImageModel {
|
|||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let updated_path = updated_path.to_string();
|
||||
let result = query!("UPDATE images SET filePath = ? where id = ?", updated_path, index)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
let result = query!(
|
||||
"UPDATE images SET file_path = ? where id = ?",
|
||||
updated_path,
|
||||
index
|
||||
)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_i) => {
|
||||
for image in self
|
||||
|
@ -427,9 +444,11 @@ impl image_model::ImageModel {
|
|||
.filter(|x| x.id == index)
|
||||
{
|
||||
image.path = updated_path.clone();
|
||||
debug!(title = image.title,
|
||||
path = updated_path,
|
||||
"updated image path");
|
||||
debug!(
|
||||
title = image.title,
|
||||
path = updated_path,
|
||||
"updated image path"
|
||||
);
|
||||
}
|
||||
self.as_mut().data_changed(
|
||||
model_index,
|
||||
|
@ -441,7 +460,7 @@ impl image_model::ImageModel {
|
|||
Err(e) => {
|
||||
error!("Error connecting to db: {e}");
|
||||
false
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue