fix: preserve data wherever possible

This commit is contained in:
silver 2023-09-18 00:03:25 +01:00
parent ab2c695409
commit 3bf085204e

View file

@ -91,8 +91,9 @@ fn get_csv(config: &Config) -> Result<Vec<Csv>, Box<dyn std::error::Error>> {
async fn add_users_wolves_csv(db: &Pool<Sqlite>, server: &GuildId, user: &Csv) { async fn add_users_wolves_csv(db: &Pool<Sqlite>, server: &GuildId, user: &Csv) {
match sqlx::query_as::<_, Wolves>( match sqlx::query_as::<_, Wolves>(
" "
INSERT OR REPLACE INTO wolves (id_wolves, email) INSERT INTO wolves (id_wolves, email)
VALUES (?1, ?2) VALUES ($1, $2)
ON CONFLICT(id_wolves) DO UPDATE SET email = $2
", ",
) )
.bind(&user.wolves.id_wolves) .bind(&user.wolves.id_wolves)
@ -177,11 +178,7 @@ async fn get_wolves(db: &Pool<Sqlite>) {
} = server_config; } = server_config;
// get the data here // get the data here
let result: Vec<WolvesResult> = vec![WolvesResult { let result: Vec<WolvesResult> = vec![];
id_wolves: "12345".to_string(),
email: "ul.wolves2@brendan.ie".to_string(),
expiry: "2024-08-31".to_string(),
}];
for user in result { for user in result {
add_users_wolves(db, &server, &user).await; add_users_wolves(db, &server, &user).await;
@ -193,8 +190,9 @@ async fn add_users_wolves(db: &Pool<Sqlite>, server: &GuildId, user: &WolvesResu
// expiry // expiry
match sqlx::query_as::<_, Wolves>( match sqlx::query_as::<_, Wolves>(
" "
INSERT OR REPLACE INTO wolves (id_wolves, email) INSERT INTO wolves (id_wolves, email)
VALUES (?1, ?2) VALUES ($1, $2)
ON CONFLICT(id_wolves) DO UPDATE SET email = $2
", ",
) )
.bind(&user.id_wolves) .bind(&user.id_wolves)