From 3bf085204e9f93bfd96217b4969e4da9090f66b0 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Mon, 18 Sep 2023 00:03:25 +0100 Subject: [PATCH] fix: preserve data wherever possible --- src/bin/update_data.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/bin/update_data.rs b/src/bin/update_data.rs index 2b1d1f7..1fc25de 100644 --- a/src/bin/update_data.rs +++ b/src/bin/update_data.rs @@ -91,8 +91,9 @@ fn get_csv(config: &Config) -> Result, Box> { async fn add_users_wolves_csv(db: &Pool, server: &GuildId, user: &Csv) { match sqlx::query_as::<_, Wolves>( " - INSERT OR REPLACE INTO wolves (id_wolves, email) - VALUES (?1, ?2) + INSERT INTO wolves (id_wolves, email) + VALUES ($1, $2) + ON CONFLICT(id_wolves) DO UPDATE SET email = $2 ", ) .bind(&user.wolves.id_wolves) @@ -177,11 +178,7 @@ async fn get_wolves(db: &Pool) { } = server_config; // get the data here - let result: Vec = vec![WolvesResult { - id_wolves: "12345".to_string(), - email: "ul.wolves2@brendan.ie".to_string(), - expiry: "2024-08-31".to_string(), - }]; + let result: Vec = vec![]; for user in result { add_users_wolves(db, &server, &user).await; @@ -193,8 +190,9 @@ async fn add_users_wolves(db: &Pool, server: &GuildId, user: &WolvesResu // expiry match sqlx::query_as::<_, Wolves>( " - INSERT OR REPLACE INTO wolves (id_wolves, email) - VALUES (?1, ?2) + INSERT INTO wolves (id_wolves, email) + VALUES ($1, $2) + ON CONFLICT(id_wolves) DO UPDATE SET email = $2 ", ) .bind(&user.id_wolves)