finishing video_model transition to sqlx
This commit is contained in:
parent
df07b13b28
commit
a697e4d89c
1 changed files with 127 additions and 97 deletions
|
@ -180,7 +180,7 @@ mod video_model {
|
|||
|
||||
use cxx_qt::{CxxQtType, Threading};
|
||||
use cxx_qt_lib::{QByteArray, QModelIndex, QString, QUrl, QVariant};
|
||||
use sqlx::{query, query_as, SqliteConnection};
|
||||
use sqlx::{query, query_as, Connection, SqliteConnection};
|
||||
use std::path::PathBuf;
|
||||
use std::pin::Pin;
|
||||
use tracing::{debug, error};
|
||||
|
@ -256,7 +256,6 @@ impl video_model::VideoModel {
|
|||
return false;
|
||||
}
|
||||
let video_id = self.videos.get(index as usize).unwrap().id;
|
||||
let thread = self.qt_thread();
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
|
||||
rt.block_on(async {
|
||||
|
@ -462,10 +461,11 @@ impl video_model::VideoModel {
|
|||
let model_index =
|
||||
&self.as_ref().index(index, 0, &QModelIndex::default());
|
||||
|
||||
let db = &mut self.as_mut().get_db();
|
||||
let result = update(videos.filter(id.eq(index)))
|
||||
.set(end_time.eq(updated_end_time))
|
||||
.execute(db);
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let result = query!("UPDATE videos SET endTime = ? where id = ?", updated_end_time, index)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_i) => {
|
||||
for video in self
|
||||
|
@ -476,17 +476,24 @@ impl video_model::VideoModel {
|
|||
.filter(|x| x.id == index)
|
||||
{
|
||||
video.end_time = updated_end_time;
|
||||
debug!(title = video.title,
|
||||
end_time = updated_end_time,
|
||||
"updated video end_time");
|
||||
}
|
||||
self.as_mut().data_changed(
|
||||
model_index,
|
||||
model_index,
|
||||
&vector_roles,
|
||||
);
|
||||
println!("rust-end-time: {updated_end_time:?}");
|
||||
true
|
||||
}
|
||||
Err(_e) => false,
|
||||
Err(e) => {
|
||||
error!("Error connecting to db: {e}");
|
||||
false
|
||||
},
|
||||
}
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
pub fn update_start_time(
|
||||
|
@ -500,10 +507,11 @@ impl video_model::VideoModel {
|
|||
let model_index =
|
||||
&self.as_ref().index(index, 0, &QModelIndex::default());
|
||||
|
||||
let db = &mut self.as_mut().get_db();
|
||||
let result = update(videos.filter(id.eq(index)))
|
||||
.set(start_time.eq(updated_start_time))
|
||||
.execute(db);
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let result = query!("UPDATE videos SET startTime = ? where id = ?", updated_start_time, index)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_i) => {
|
||||
for video in self
|
||||
|
@ -514,17 +522,24 @@ impl video_model::VideoModel {
|
|||
.filter(|x| x.id == index)
|
||||
{
|
||||
video.start_time = updated_start_time;
|
||||
debug!(title = video.title,
|
||||
start_time = updated_start_time,
|
||||
"updated video start_time");
|
||||
}
|
||||
self.as_mut().data_changed(
|
||||
model_index,
|
||||
model_index,
|
||||
&vector_roles,
|
||||
);
|
||||
println!("rust-start-time: {:?}", updated_start_time);
|
||||
true
|
||||
}
|
||||
Err(_e) => false,
|
||||
Err(e) => {
|
||||
error!("Error connecting to db: {e}");
|
||||
false
|
||||
},
|
||||
}
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
pub fn update_title(
|
||||
|
@ -538,10 +553,12 @@ impl video_model::VideoModel {
|
|||
let model_index =
|
||||
&self.as_ref().index(index, 0, &QModelIndex::default());
|
||||
|
||||
let db = &mut self.as_mut().get_db();
|
||||
let result = update(videos.filter(id.eq(index)))
|
||||
.set(title.eq(updated_title.to_string()))
|
||||
.execute(db);
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let title = updated_title.to_string();
|
||||
let result = query!("UPDATE videos SET title = ? where id = ?", title, index)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_i) => {
|
||||
for video in self
|
||||
|
@ -551,20 +568,25 @@ impl video_model::VideoModel {
|
|||
.iter_mut()
|
||||
.filter(|x| x.id == index)
|
||||
{
|
||||
video.title = updated_title.clone().to_string();
|
||||
println!("rust-title: {:?}", video.title);
|
||||
video.title = title.clone();
|
||||
debug!(title = video.title,
|
||||
title = title,
|
||||
"updated video title");
|
||||
}
|
||||
// TODO this seems to not be updating in the actual list
|
||||
self.as_mut().data_changed(
|
||||
model_index,
|
||||
model_index,
|
||||
&vector_roles,
|
||||
);
|
||||
println!("rust-title: {:?}", updated_title);
|
||||
true
|
||||
}
|
||||
Err(_e) => false,
|
||||
Err(e) => {
|
||||
error!("Error connecting to db: {e}");
|
||||
false
|
||||
},
|
||||
}
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
pub fn update_path(
|
||||
|
@ -577,10 +599,12 @@ impl video_model::VideoModel {
|
|||
let model_index =
|
||||
&self.as_ref().index(index, 0, &QModelIndex::default());
|
||||
|
||||
let db = &mut self.as_mut().get_db();
|
||||
let result = update(videos.filter(id.eq(index)))
|
||||
.set(path.eq(updated_path.to_string()))
|
||||
.execute(db);
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let updated_path = updated_path.to_string();
|
||||
let result = query!("UPDATE videos SET filePath = ? where id = ?", updated_path, index)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_i) => {
|
||||
for video in self
|
||||
|
@ -590,19 +614,25 @@ impl video_model::VideoModel {
|
|||
.iter_mut()
|
||||
.filter(|x| x.id == index)
|
||||
{
|
||||
video.path = updated_path.clone().to_string();
|
||||
println!("rust-title: {:?}", video.title);
|
||||
video.path = updated_path.clone();
|
||||
debug!(title = video.title,
|
||||
path = updated_path,
|
||||
"updated video path");
|
||||
}
|
||||
self.as_mut().data_changed(
|
||||
model_index,
|
||||
model_index,
|
||||
&vector_roles,
|
||||
);
|
||||
println!("rust-path: {:?}", updated_path);
|
||||
true
|
||||
}
|
||||
Err(_e) => false,
|
||||
Err(e) => {
|
||||
error!("Error connecting to db: {e}");
|
||||
false
|
||||
},
|
||||
}
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
fn search(mut self: Pin<&mut Self>, search_term: QString) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue