trying to tweak sqlx

This commit is contained in:
Chris Cochrun 2025-02-27 15:30:08 -06:00
parent 4fe68236ea
commit 804850505e
11 changed files with 129 additions and 219 deletions

1
.envrc
View file

@ -1,3 +1,4 @@
DATABASE_URL="sqlite:///home/chris/.local/share/lumina/library-db.sqlite3"
use flake . --impure use flake . --impure
# eval $(guix shell -D --search-paths) # eval $(guix shell -D --search-paths)

View file

@ -1,38 +0,0 @@
{
"db_name": "SQLite",
"query": "SELECT id as \"id: i32\", title, file_path as \"path\", html from presentations",
"describe": {
"columns": [
{
"name": "id: i32",
"ordinal": 0,
"type_info": "Integer"
},
{
"name": "title",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "path",
"ordinal": 2,
"type_info": "Text"
},
{
"name": "html",
"ordinal": 3,
"type_info": "Bool"
}
],
"parameters": {
"Right": 0
},
"nullable": [
false,
false,
false,
false
]
},
"hash": "7ace613c138f874198ea8e5f72697d4c604fe7b755fdcb6773692c813b5e1d4b"
}

View file

@ -1,32 +0,0 @@
{
"db_name": "SQLite",
"query": "SELECT title as \"title!\", file_path as \"path!\", id as \"id: i32\" from images",
"describe": {
"columns": [
{
"name": "title!",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "path!",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "id: i32",
"ordinal": 2,
"type_info": "Integer"
}
],
"parameters": {
"Right": 0
},
"nullable": [
false,
false,
false
]
},
"hash": "8cc171f2be70148e4178fa23d34887be69527e6fda128b11a6279cd8cf410918"
}

View file

@ -1,32 +0,0 @@
{
"db_name": "SQLite",
"query": "SELECT title as \"title!\", file_path as \"path!\", id as \"id: i32\" from images where id = ?",
"describe": {
"columns": [
{
"name": "title!",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "path!",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "id: i32",
"ordinal": 2,
"type_info": "Integer"
}
],
"parameters": {
"Right": 1
},
"nullable": [
false,
false,
false
]
},
"hash": "aa01b675a8e40d152144b3b6a11ec9c68244defd5ea85764979535e1b2267496"
}

View file

@ -1,50 +0,0 @@
{
"db_name": "SQLite",
"query": "SELECT title as \"title!\", file_path as \"path!\", start_time as \"start_time!: f32\", end_time as \"end_time!: f32\", loop as \"looping!\", id as \"id: i32\" from videos where id = ?",
"describe": {
"columns": [
{
"name": "title!",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "path!",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "start_time!: f32",
"ordinal": 2,
"type_info": "Null"
},
{
"name": "end_time!: f32",
"ordinal": 3,
"type_info": "Null"
},
{
"name": "looping!",
"ordinal": 4,
"type_info": "Bool"
},
{
"name": "id: i32",
"ordinal": 5,
"type_info": "Integer"
}
],
"parameters": {
"Right": 1
},
"nullable": [
false,
false,
true,
true,
false,
false
]
},
"hash": "d4b324ece51b3a314367f570bb7f28a36ef703387d3f9eace9f51f102b1ed6da"
}

View file

@ -1,50 +0,0 @@
{
"db_name": "SQLite",
"query": "SELECT title as \"title!\", file_path as \"path!\", start_time as \"start_time!: f32\", end_time as \"end_time!: f32\", loop as \"looping!\", id as \"id: i32\" from videos",
"describe": {
"columns": [
{
"name": "title!",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "path!",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "start_time!: f32",
"ordinal": 2,
"type_info": "Float"
},
{
"name": "end_time!: f32",
"ordinal": 3,
"type_info": "Float"
},
{
"name": "looping!",
"ordinal": 4,
"type_info": "Bool"
},
{
"name": "id: i32",
"ordinal": 5,
"type_info": "Integer"
}
],
"parameters": {
"Right": 0
},
"nullable": [
false,
false,
true,
true,
false,
false
]
},
"hash": "f6c1c41a68b04f939301d6bb897cf79915ef389eedb009daef3be737709266f8"
}

View file

@ -83,6 +83,7 @@
pkgs.libxkbcommon pkgs.libxkbcommon
] ]
}"; }";
DATABASE_URL = "sqlite:///home/chris/.local/share/lumina/library-db.sqlite3";
}; };
defaultPackage = naersk'.buildPackage { defaultPackage = naersk'.buildPackage {
src = ./.; src = ./.;

View file

@ -374,6 +374,24 @@ pub async fn get_song_from_db(
} }
impl Model<Song> { impl Model<Song> {
pub async fn update_song(
&mut self,
item: Song,
index: i32,
db: &mut SqliteConnection,
) -> Result<()> {
self.update_item(item, index)?;
query!(
r#"UPDATE songs SET title = {} WHERE id = {}"#,
item.title,
item.id
)
.fetch_one(db)
.await?;
Ok(())
}
pub async fn new_song_model(db: &mut SqliteConnection) -> Self { pub async fn new_song_model(db: &mut SqliteConnection) -> Self {
let mut model = Self { let mut model = Self {
items: vec![], items: vec![],

View file

@ -418,17 +418,114 @@ impl cosmic::Application for App {
Message::SongEditor(message) => { Message::SongEditor(message) => {
debug!(?message); debug!(?message);
match message { match message {
song_editor::Message::UpdateSong(ref song) => { song_editor::Message::ChangeFont(ref font) => {
debug!(?song); if let Some(mut song) =
if let Some(library) = self.library.as_mut() { self.song_editor.song.clone()
match library.update_song(song.clone()) { {
Ok(_) => { song.font = Some(font.to_string());
debug!("upated song") self.song_editor.song =
Some(song.clone());
if let Some(library) = &mut self.library {
match library.update_song(song) {
Ok(_) => (),
Err(e) => error!(?e),
} }
Err(e) => error!(?e), };
}
}; };
} }
song_editor::Message::ChangeFontSize(
font_size,
) => {
if let Some(mut song) =
self.song_editor.song.clone()
{
song.font_size = Some(font_size as i32);
self.song_editor.song =
Some(song.clone());
if let Some(library) = &mut self.library {
match library.update_song(song) {
Ok(_) => (),
Err(e) => error!(?e),
}
};
};
}
song_editor::Message::ChangeTitle(ref title) => {
if let Some(mut song) =
self.song_editor.song.clone()
{
song.title = title.to_string();
self.song_editor.song =
Some(song.clone());
if let Some(library) = &mut self.library {
match library.update_song(song) {
Ok(_) => (),
Err(e) => error!(?e),
}
};
};
}
song_editor::Message::ChangeVerseOrder(
ref vo,
) => {
if let Some(mut song) =
self.song_editor.song.clone()
{
let verse_order = vo
.split(" ")
.into_iter()
.map(|s| s.to_owned())
.collect();
song.verse_order = Some(verse_order);
self.song_editor.song =
Some(song.clone());
if let Some(library) = &mut self.library {
match library.update_song(song) {
Ok(_) => (),
Err(e) => error!(?e),
}
};
};
}
song_editor::Message::ChangeLyrics(
ref action,
) => {
self.song_editor
.lyrics
.perform(action.clone());
let lyrics = self.song_editor.lyrics.text();
if let Some(mut song) =
self.song_editor.song.clone()
{
song.lyrics = Some(lyrics.to_string());
self.song_editor.song =
Some(song.clone());
if let Some(library) = &mut self.library {
match library.update_song(song) {
Ok(_) => (),
Err(e) => error!(?e),
}
};
};
}
song_editor::Message::ChangeAuthor(
ref author,
) => {
if let Some(mut song) =
self.song_editor.song.clone()
{
song.author = Some(author.to_string());
self.song_editor.song =
Some(song.clone());
if let Some(library) = &mut self.library {
match library.update_song(song) {
Ok(_) => (),
Err(e) => error!(?e),
}
};
};
}
song_editor::Message::Edit(_) => todo!(),
_ => (), _ => (),
}; };
self.song_editor.update(message).map(|m| { self.song_editor.update(message).map(|m| {

View file

@ -79,6 +79,7 @@ impl Library {
Message::RemoveItem => Task::none(), Message::RemoveItem => Task::none(),
Message::OpenItem(item) => { Message::OpenItem(item) => {
debug!(?item); debug!(?item);
self.editing_item = item;
Task::none() Task::none()
} }
Message::HoverLibrary(library_kind) => { Message::HoverLibrary(library_kind) => {

View file

@ -26,7 +26,7 @@ use super::presenter::slide_view;
#[derive(Debug)] #[derive(Debug)]
pub struct SongEditor { pub struct SongEditor {
song: Option<Song>, pub song: Option<Song>,
title: String, title: String,
fonts: combo_box::State<String>, fonts: combo_box::State<String>,
font_sizes: Vec<String>, font_sizes: Vec<String>,
@ -35,7 +35,7 @@ pub struct SongEditor {
audio: PathBuf, audio: PathBuf,
font_size: usize, font_size: usize,
verse_order: String, verse_order: String,
lyrics: text_editor::Content, pub lyrics: text_editor::Content,
editing: bool, editing: bool,
background: Option<Background>, background: Option<Background>,
video: Option<Video>, video: Option<Video>,
@ -157,13 +157,7 @@ impl SongEditor {
} }
Message::ChangeTitle(title) => { Message::ChangeTitle(title) => {
self.title = title.clone(); self.title = title.clone();
if let Some(mut song) = self.song.clone() { Task::none()
debug!(title);
song.title = title;
self.update(Message::UpdateSong(song))
} else {
Task::none()
}
} }
Message::ChangeVerseOrder(verse_order) => { Message::ChangeVerseOrder(verse_order) => {
self.verse_order = verse_order.clone(); self.verse_order = verse_order.clone();