trying to tweak sqlx
This commit is contained in:
parent
4fe68236ea
commit
804850505e
1
.envrc
1
.envrc
|
@ -1,3 +1,4 @@
|
|||
DATABASE_URL="sqlite:///home/chris/.local/share/lumina/library-db.sqlite3"
|
||||
use flake . --impure
|
||||
# eval $(guix shell -D --search-paths)
|
||||
|
||||
|
|
|
@ -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"
|
||||
}
|
|
@ -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"
|
||||
}
|
|
@ -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"
|
||||
}
|
|
@ -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"
|
||||
}
|
|
@ -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"
|
||||
}
|
|
@ -83,6 +83,7 @@
|
|||
pkgs.libxkbcommon
|
||||
]
|
||||
}";
|
||||
DATABASE_URL = "sqlite:///home/chris/.local/share/lumina/library-db.sqlite3";
|
||||
};
|
||||
defaultPackage = naersk'.buildPackage {
|
||||
src = ./.;
|
||||
|
|
|
@ -374,6 +374,24 @@ pub async fn get_song_from_db(
|
|||
}
|
||||
|
||||
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 {
|
||||
let mut model = Self {
|
||||
items: vec![],
|
||||
|
|
111
src/main.rs
111
src/main.rs
|
@ -418,17 +418,114 @@ impl cosmic::Application for App {
|
|||
Message::SongEditor(message) => {
|
||||
debug!(?message);
|
||||
match message {
|
||||
song_editor::Message::UpdateSong(ref song) => {
|
||||
debug!(?song);
|
||||
if let Some(library) = self.library.as_mut() {
|
||||
match library.update_song(song.clone()) {
|
||||
Ok(_) => {
|
||||
debug!("upated song")
|
||||
}
|
||||
song_editor::Message::ChangeFont(ref font) => {
|
||||
if let Some(mut song) =
|
||||
self.song_editor.song.clone()
|
||||
{
|
||||
song.font = Some(font.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::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| {
|
||||
|
|
|
@ -79,6 +79,7 @@ impl Library {
|
|||
Message::RemoveItem => Task::none(),
|
||||
Message::OpenItem(item) => {
|
||||
debug!(?item);
|
||||
self.editing_item = item;
|
||||
Task::none()
|
||||
}
|
||||
Message::HoverLibrary(library_kind) => {
|
||||
|
|
|
@ -26,7 +26,7 @@ use super::presenter::slide_view;
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct SongEditor {
|
||||
song: Option<Song>,
|
||||
pub song: Option<Song>,
|
||||
title: String,
|
||||
fonts: combo_box::State<String>,
|
||||
font_sizes: Vec<String>,
|
||||
|
@ -35,7 +35,7 @@ pub struct SongEditor {
|
|||
audio: PathBuf,
|
||||
font_size: usize,
|
||||
verse_order: String,
|
||||
lyrics: text_editor::Content,
|
||||
pub lyrics: text_editor::Content,
|
||||
editing: bool,
|
||||
background: Option<Background>,
|
||||
video: Option<Video>,
|
||||
|
@ -157,14 +157,8 @@ impl SongEditor {
|
|||
}
|
||||
Message::ChangeTitle(title) => {
|
||||
self.title = title.clone();
|
||||
if let Some(mut song) = self.song.clone() {
|
||||
debug!(title);
|
||||
song.title = title;
|
||||
self.update(Message::UpdateSong(song))
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
Message::ChangeVerseOrder(verse_order) => {
|
||||
self.verse_order = verse_order.clone();
|
||||
if let Some(mut song) = self.song.clone() {
|
||||
|
|
Loading…
Reference in a new issue