Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 2cc1f36d rédigé par Kubat's avatar Kubat
Parcourir les fichiers

DB: Type the kara tags and info in the db functions

parent 5963cb2f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -1745,6 +1745,7 @@ dependencies = [ ...@@ -1745,6 +1745,7 @@ dependencies = [
"commons", "commons",
"diesel", "diesel",
"diesel_migrations", "diesel_migrations",
"hashbrown 0.13.2",
"kurisu_api", "kurisu_api",
"lektor_c_compat", "lektor_c_compat",
"serde", "serde",
......
...@@ -11,6 +11,7 @@ doctest = false ...@@ -11,6 +11,7 @@ doctest = false
[dependencies] [dependencies]
serde.workspace = true serde.workspace = true
thiserror.workspace = true thiserror.workspace = true
hashbrown.workspace = true
diesel_migrations = "2" diesel_migrations = "2"
diesel = { version = "2", default-features = false, features = ["sqlite"] } diesel = { version = "2", default-features = false, features = ["sqlite"] }
......
use crate::{models::*, uri::LktUri, *}; use crate::{models::*, types::*, uri::LktUri, *};
use diesel::connection::DefaultLoadingMode; use hashbrown::HashMap;
use kurisu_api::v1 as api_v1; use kurisu_api::v1 as api_v1;
/// Create a connexion to a database and run automatically the migrations. /// Create a connexion to a database and run automatically the migrations.
...@@ -275,39 +275,52 @@ impl LktDatabaseConnection { ...@@ -275,39 +275,52 @@ impl LktDatabaseConnection {
} }
} }
/// Get basic information about a kara, like its source, title, origin, the
/// laguages, etc. Here we don't get the kara makers as it's not an
/// essential information.
pub fn get_kara_info(&mut self, local_id: i64) -> LktDatabaseResult<KaraInfo> {
todo!("get info for kara {local_id}")
}
/// Get all infos about a kara, its metadata, its tags, repo, repo id, /// Get all infos about a kara, its metadata, its tags, repo, repo id,
/// languages, karamakers... /// karamakers...
pub fn get_kara_info( pub fn get_kara_tags(&mut self, local_id: i64) -> LktDatabaseResult<KaraTags> {
&mut self, let (repo, repo_id) = with_dsl!(repo_kara => repo_kara
local_id: i64,
) -> LktDatabaseResult<Vec<(String, Option<String>)>> {
let repo: String = with_dsl!(repo_kara => repo_kara
.filter(local_kara_id.is(local_id)) .filter(local_kara_id.is(local_id))
.inner_join(schema::repo::table) .inner_join(schema::repo::table)
.select(schema::repo::name) .select((schema::repo::name, repo_kara_id))
.first::<String>(&mut self.sqlite)? .first::<(String, i64)>(&mut self.sqlite)?
); );
let mut ret = vec![(String::from("repo"), Some(repo))];
for kara_maker in with_dsl!(kara => kara let kara_makers: Vec<String> = with_dsl!(kara => kara
.filter(id.is(local_id)) .filter(id.is(local_id))
.inner_join(schema::kara_maker::table) .inner_join(schema::kara_maker::table)
.select(schema::kara_maker::name) .select(schema::kara_maker::name)
.load_iter::<String, DefaultLoadingMode>(&mut self.sqlite)? .load::<String>(&mut self.sqlite)?
) { );
ret.push((String::from("karamaker"), Some(kara_maker?)));
}
for tag_entry in with_dsl!(kara_tag => kara_tag let tags_raw: Vec<(String, Option<String>)> = with_dsl!(kara_tag => kara_tag
.filter(kara_id.is(local_id)) .filter(kara_id.is(local_id))
.inner_join(schema::tag::table) .inner_join(schema::tag::table)
.select((schema::tag::name, value)) .select((schema::tag::name, value))
.load_iter::<(String, Option<String>), DefaultLoadingMode>(&mut self.sqlite)? .load::<(String, Option<String>)>(&mut self.sqlite)?
) { );
let (key, value) = tag_entry?; let mut tags: HashMap<String, Vec<String>> = Default::default();
ret.push((key, value)) for (tag, value) in tags_raw.into_iter() {
match tags.get_mut(&tag) {
Some(values) => values.extend(value),
None => {
let values: Vec<_> = value.into_iter().collect();
tags.insert(tag, values);
}
}
} }
Ok(ret) Ok(KaraTags {
repo,
repo_id,
kara_makers,
tags,
})
} }
} }
...@@ -6,6 +6,7 @@ pub mod connexion; ...@@ -6,6 +6,7 @@ pub mod connexion;
pub mod error; pub mod error;
pub mod models; pub mod models;
pub mod queue; pub mod queue;
pub mod types;
pub mod uri; pub mod uri;
pub(self) mod schema; pub(self) mod schema;
......
use hashbrown::HashMap;
pub struct KaraInfo {
pub local_id: i64,
pub source_name: String,
pub song_title: String,
pub song_origin: String,
pub song_type: String,
pub languages: Vec<String>,
}
pub struct KaraTags {
pub repo_id: i64,
pub repo: String,
pub kara_makers: Vec<String>,
pub tags: HashMap<String, Vec<String>>,
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter