changed to how the guild query works so that errors are more useful and it doesnt do dumb shit

This commit is contained in:
jude 2020-10-27 17:35:01 +00:00
parent 75653a3e88
commit db56118bfb
3 changed files with 34 additions and 27 deletions

2
Cargo.lock generated
View File

@ -1175,7 +1175,7 @@ dependencies = [
[[package]]
name = "reminder_rs"
version = "1.1.4"
version = "1.1.5"
dependencies = [
"Inflector",
"async-trait",

View File

@ -1,6 +1,6 @@
[package]
name = "reminder_rs"
version = "1.1.4"
version = "1.1.5"
authors = ["jellywx <judesouthworth@pm.me>"]
edition = "2018"

View File

@ -41,13 +41,10 @@ SELECT prefix FROM guilds WHERE guild = ?
}
}
pub async fn from_guild(
guild: Guild,
pool: &MySqlPool,
) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> {
pub async fn from_guild(guild: Guild, pool: &MySqlPool) -> Result<Self, sqlx::Error> {
let guild_id = guild.id.as_u64().to_owned();
if let Ok(g) = sqlx::query_as!(
match sqlx::query_as!(
Self,
"
SELECT id, name, prefix FROM guilds WHERE guild = ?
@ -57,10 +54,13 @@ SELECT id, name, prefix FROM guilds WHERE guild = ?
.fetch_one(pool)
.await
{
g.name = guild.name;
Ok(mut g) => {
g.name = Some(guild.name);
Ok(g)
} else {
}
Err(sqlx::Error::RowNotFound) => {
sqlx::query!(
"
INSERT INTO guilds (guild, name, prefix) VALUES (?, ?, ?)
@ -82,6 +82,13 @@ SELECT id, name, prefix FROM guilds WHERE guild = ?
.fetch_one(pool)
.await?)
}
Err(e) => {
error!("Unexpected error in guild query: {:?}", e);
Err(e)
}
}
}
pub async fn commit_changes(&self, pool: &MySqlPool) {