Fix queries, also add error message for database (#152)
This commit is contained in:
parent
f887f5dca3
commit
e33738a876
1040
sqlx-data.json
1040
sqlx-data.json
File diff suppressed because it is too large
Load Diff
@ -409,7 +409,7 @@ impl Mod {
|
|||||||
m.issues_url issues_url, m.source_url source_url, m.wiki_url wiki_url, m.discord_url discord_url, m.license_url license_url,
|
m.issues_url issues_url, m.source_url source_url, m.wiki_url wiki_url, m.discord_url discord_url, m.license_url license_url,
|
||||||
m.team_id team_id, m.client_side client_side, m.server_side server_side, m.license license, m.slug slug,
|
m.team_id team_id, m.client_side client_side, m.server_side server_side, m.license license, m.slug slug,
|
||||||
s.status status_name, cs.name client_side_type, ss.name server_side_type, l.short short, l.name license_name,
|
s.status status_name, cs.name client_side_type, ss.name server_side_type, l.short short, l.name license_name,
|
||||||
ARRAY_AGG( DISTINCT c.category) categories, ARRAY_AGG(DISTINCT v.id) versions
|
STRING_AGG(DISTINCT c.category, ',') categories, STRING_AGG(DISTINCT v.id::text, ',') versions
|
||||||
FROM mods m
|
FROM mods m
|
||||||
LEFT OUTER JOIN mods_categories mc ON joining_mod_id = m.id
|
LEFT OUTER JOIN mods_categories mc ON joining_mod_id = m.id
|
||||||
LEFT OUTER JOIN categories c ON mc.joining_category_id = c.id
|
LEFT OUTER JOIN categories c ON mc.joining_category_id = c.id
|
||||||
@ -450,13 +450,17 @@ impl Mod {
|
|||||||
slug: m.slug.clone(),
|
slug: m.slug.clone(),
|
||||||
body: m.body.clone(),
|
body: m.body.clone(),
|
||||||
},
|
},
|
||||||
categories: m.categories.clone().unwrap_or_default(),
|
categories: m
|
||||||
|
.categories
|
||||||
|
.unwrap_or_default()
|
||||||
|
.split(",")
|
||||||
|
.map(|x| x.to_string())
|
||||||
|
.collect(),
|
||||||
versions: m
|
versions: m
|
||||||
.versions
|
.versions
|
||||||
.clone()
|
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.into_iter()
|
.split(",")
|
||||||
.map(VersionId)
|
.map(|x| VersionId(x.parse().unwrap_or_default()))
|
||||||
.collect(),
|
.collect(),
|
||||||
donation_urls: vec![],
|
donation_urls: vec![],
|
||||||
status: crate::models::mods::ModStatus::from_str(&m.status_name),
|
status: crate::models::mods::ModStatus::from_str(&m.status_name),
|
||||||
@ -488,7 +492,7 @@ impl Mod {
|
|||||||
m.issues_url issues_url, m.source_url source_url, m.wiki_url wiki_url, m.discord_url discord_url, m.license_url license_url,
|
m.issues_url issues_url, m.source_url source_url, m.wiki_url wiki_url, m.discord_url discord_url, m.license_url license_url,
|
||||||
m.team_id team_id, m.client_side client_side, m.server_side server_side, m.license license, m.slug slug,
|
m.team_id team_id, m.client_side client_side, m.server_side server_side, m.license license, m.slug slug,
|
||||||
s.status status_name, cs.name client_side_type, ss.name server_side_type, l.short short, l.name license_name,
|
s.status status_name, cs.name client_side_type, ss.name server_side_type, l.short short, l.name license_name,
|
||||||
ARRAY_AGG( DISTINCT c.category) categories, ARRAY_AGG(DISTINCT v.id) versions
|
STRING_AGG(DISTINCT c.category, ',') categories, STRING_AGG(DISTINCT v.id::text, ',') versions
|
||||||
FROM mods m
|
FROM mods m
|
||||||
LEFT OUTER JOIN mods_categories mc ON joining_mod_id = m.id
|
LEFT OUTER JOIN mods_categories mc ON joining_mod_id = m.id
|
||||||
LEFT OUTER JOIN categories c ON mc.joining_category_id = c.id
|
LEFT OUTER JOIN categories c ON mc.joining_category_id = c.id
|
||||||
@ -527,8 +531,8 @@ impl Mod {
|
|||||||
slug: m.slug.clone(),
|
slug: m.slug.clone(),
|
||||||
body: m.body.clone(),
|
body: m.body.clone(),
|
||||||
},
|
},
|
||||||
categories: m.categories.clone().unwrap_or_default(),
|
categories: m.categories.unwrap_or_default().split(",").map(|x| x.to_string()).collect(),
|
||||||
versions: m.versions.clone().unwrap_or_default().into_iter().map(VersionId).collect(),
|
versions: m.versions.unwrap_or_default().split(",").map(|x| VersionId(x.parse().unwrap_or_default())).collect(),
|
||||||
donation_urls: vec![],
|
donation_urls: vec![],
|
||||||
status: crate::models::mods::ModStatus::from_str(&m.status_name),
|
status: crate::models::mods::ModStatus::from_str(&m.status_name),
|
||||||
license_id: m.short,
|
license_id: m.short,
|
||||||
|
|||||||
@ -466,9 +466,9 @@ impl Version {
|
|||||||
SELECT v.id id, v.mod_id mod_id, v.author_id author_id, v.name version_name, v.version_number version_number,
|
SELECT v.id id, v.mod_id mod_id, v.author_id author_id, v.name version_name, v.version_number version_number,
|
||||||
v.changelog changelog, v.changelog_url changelog_url, v.date_published date_published, v.downloads downloads,
|
v.changelog changelog, v.changelog_url changelog_url, v.date_published date_published, v.downloads downloads,
|
||||||
rc.channel release_channel, v.featured featured,
|
rc.channel release_channel, v.featured featured,
|
||||||
ARRAY_AGG(DISTINCT gv.version) game_versions, ARRAY_AGG(DISTINCT l.loader) loaders,
|
STRING_AGG(DISTINCT gv.version, ',') game_versions, STRING_AGG(DISTINCT l.loader, ',') loaders,
|
||||||
ARRAY_AGG(DISTINCT f.id || ', ' || f.filename || ', ' || f.is_primary || ', ' || f.url) files,
|
STRING_AGG(DISTINCT f.id || ', ' || f.filename || ', ' || f.is_primary || ', ' || f.url, ' ,') files,
|
||||||
ARRAY_AGG(DISTINCT h.algorithm || ', ' || encode(h.hash, 'escape') || ', ' || h.file_id) hashes
|
STRING_AGG(DISTINCT h.algorithm || ', ' || encode(h.hash, 'escape') || ', ' || h.file_id, ' ,') hashes
|
||||||
FROM versions v
|
FROM versions v
|
||||||
INNER JOIN release_channels rc on v.release_channel = rc.id
|
INNER JOIN release_channels rc on v.release_channel = rc.id
|
||||||
LEFT OUTER JOIN game_versions_versions gvv on v.id = gvv.joining_version_id
|
LEFT OUTER JOIN game_versions_versions gvv on v.id = gvv.joining_version_id
|
||||||
@ -488,7 +488,7 @@ impl Version {
|
|||||||
if let Some(v) = result {
|
if let Some(v) = result {
|
||||||
let mut hashes: Vec<(FileId, String, Vec<u8>)> = Vec::new();
|
let mut hashes: Vec<(FileId, String, Vec<u8>)> = Vec::new();
|
||||||
|
|
||||||
v.hashes.unwrap_or_default().into_iter().for_each(|f| {
|
v.hashes.unwrap_or_default().split(" ,").for_each(|f| {
|
||||||
let hash: Vec<&str> = f.split(", ").collect();
|
let hash: Vec<&str> = f.split(", ").collect();
|
||||||
hashes.push((
|
hashes.push((
|
||||||
FileId(hash[2].parse().unwrap_or(0)),
|
FileId(hash[2].parse().unwrap_or(0)),
|
||||||
@ -511,7 +511,7 @@ impl Version {
|
|||||||
files: v
|
files: v
|
||||||
.files
|
.files
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.into_iter()
|
.split(" ,")
|
||||||
.map(|f| {
|
.map(|f| {
|
||||||
let file: Vec<&str> = f.split(", ").collect();
|
let file: Vec<&str> = f.split(", ").collect();
|
||||||
let file_id = FileId(file[0].parse().unwrap_or(0));
|
let file_id = FileId(file[0].parse().unwrap_or(0));
|
||||||
@ -532,8 +532,18 @@ impl Version {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
game_versions: v.game_versions.unwrap_or_default(),
|
game_versions: v
|
||||||
loaders: v.loaders.unwrap_or_default(),
|
.game_versions
|
||||||
|
.unwrap_or_default()
|
||||||
|
.split(",")
|
||||||
|
.map(|x| x.to_string())
|
||||||
|
.collect(),
|
||||||
|
loaders: v
|
||||||
|
.loaders
|
||||||
|
.unwrap_or_default()
|
||||||
|
.split(",")
|
||||||
|
.map(|x| x.to_string())
|
||||||
|
.collect(),
|
||||||
featured: v.featured,
|
featured: v.featured,
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
@ -556,9 +566,9 @@ impl Version {
|
|||||||
SELECT v.id id, v.mod_id mod_id, v.author_id author_id, v.name version_name, v.version_number version_number,
|
SELECT v.id id, v.mod_id mod_id, v.author_id author_id, v.name version_name, v.version_number version_number,
|
||||||
v.changelog changelog, v.changelog_url changelog_url, v.date_published date_published, v.downloads downloads,
|
v.changelog changelog, v.changelog_url changelog_url, v.date_published date_published, v.downloads downloads,
|
||||||
rc.channel release_channel, v.featured featured,
|
rc.channel release_channel, v.featured featured,
|
||||||
ARRAY_AGG(DISTINCT gv.version) game_versions, ARRAY_AGG(DISTINCT l.loader) loaders,
|
STRING_AGG(DISTINCT gv.version, ',') game_versions, STRING_AGG(DISTINCT l.loader, ',') loaders,
|
||||||
ARRAY_AGG(DISTINCT f.id || ', ' || f.filename || ', ' || f.is_primary || ', ' || f.url) files,
|
STRING_AGG(DISTINCT f.id || ', ' || f.filename || ', ' || f.is_primary || ', ' || f.url, ' ,') files,
|
||||||
ARRAY_AGG(DISTINCT h.algorithm || ', ' || encode(h.hash, 'escape') || ', ' || h.file_id) hashes
|
STRING_AGG(DISTINCT h.algorithm || ', ' || encode(h.hash, 'escape') || ', ' || h.file_id, ' ,') hashes
|
||||||
FROM versions v
|
FROM versions v
|
||||||
INNER JOIN release_channels rc on v.release_channel = rc.id
|
INNER JOIN release_channels rc on v.release_channel = rc.id
|
||||||
LEFT OUTER JOIN game_versions_versions gvv on v.id = gvv.joining_version_id
|
LEFT OUTER JOIN game_versions_versions gvv on v.id = gvv.joining_version_id
|
||||||
@ -577,7 +587,7 @@ impl Version {
|
|||||||
Ok(e.right().map(|v| {
|
Ok(e.right().map(|v| {
|
||||||
let mut hashes : Vec<(FileId, String, Vec<u8>)> = Vec::new();
|
let mut hashes : Vec<(FileId, String, Vec<u8>)> = Vec::new();
|
||||||
|
|
||||||
v.hashes.unwrap_or_default().into_iter().for_each(|f| {
|
v.hashes.unwrap_or_default().split(" ,").for_each(|f| {
|
||||||
let hash : Vec<&str> = f.split(", ").collect();
|
let hash : Vec<&str> = f.split(", ").collect();
|
||||||
hashes.push((FileId(hash[2].parse().unwrap_or(0)), hash[0].to_string(), hash[1].to_string().into_bytes()));
|
hashes.push((FileId(hash[2].parse().unwrap_or(0)), hash[0].to_string(), hash[1].to_string().into_bytes()));
|
||||||
});
|
});
|
||||||
@ -593,7 +603,8 @@ impl Version {
|
|||||||
date_published: v.date_published,
|
date_published: v.date_published,
|
||||||
downloads: v.downloads,
|
downloads: v.downloads,
|
||||||
release_channel: v.release_channel,
|
release_channel: v.release_channel,
|
||||||
files: v.files.unwrap_or_default().into_iter().map(|f| {
|
files: v.files.unwrap_or_default()
|
||||||
|
.split(" ,").map(|f| {
|
||||||
let file : Vec<&str> = f.split(", ").collect();
|
let file : Vec<&str> = f.split(", ").collect();
|
||||||
let file_id = FileId(file[0].parse().unwrap_or(0));
|
let file_id = FileId(file[0].parse().unwrap_or(0));
|
||||||
let mut file_hashes = HashMap::new();
|
let mut file_hashes = HashMap::new();
|
||||||
@ -612,8 +623,8 @@ impl Version {
|
|||||||
primary: file[3].parse().unwrap_or(false)
|
primary: file[3].parse().unwrap_or(false)
|
||||||
}
|
}
|
||||||
}).collect(),
|
}).collect(),
|
||||||
game_versions: v.game_versions.unwrap_or_default(),
|
game_versions: v.game_versions.unwrap_or_default().split(",").map(|x| x.to_string()).collect(),
|
||||||
loaders: v.loaders.unwrap_or_default(),
|
loaders: v.loaders.unwrap_or_default().split(",").map(|x| x.to_string()).collect(),
|
||||||
featured: v.featured,
|
featured: v.featured,
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user