feat: save wolves data in a table

This commit is contained in:
silver 2023-08-05 22:00:18 +01:00
parent dd5ebd6bd3
commit 58bf1e80fd
4 changed files with 64 additions and 59 deletions

View file

@ -14,6 +14,16 @@ use std::{
};
use tide::prelude::*;
#[derive(Debug, Deserialize, Serialize, sqlx::FromRow)]
pub struct AccountWolves {
pub id_wolves: String,
pub id_student: String,
pub email: String,
pub expiry: String,
pub name_first: String,
pub name_second: String,
}
#[derive(Debug, Clone, Deserialize, Serialize, sqlx::FromRow)]
pub struct AccountsNew {
pub mail: String,
@ -54,10 +64,9 @@ pub async fn db_init(config: &Config) -> Result<Pool<Sqlite>, Error> {
name_surname integer not null
)",
)
.execute(&pool)
.await?;
.execute(&pool)
.await?;
sqlx::query(
"CREATE TABLE IF NOT EXISTS accounts_new (
mail text primary key,
@ -264,3 +273,15 @@ async fn update_accounts(pool: &Pool<Sqlite>, config: &Config) {
pub fn random_string(len: usize) -> String {
thread_rng().sample_iter(&Alphanumeric).take(len).map(char::from).collect()
}
pub async fn get_wolves(db: &Pool<Sqlite>) -> Vec<AccountWolves> {
sqlx::query_as::<_, AccountWolves>(
r#"
SELECT *
FROM accounts_wolves
"#,
)
.fetch_all(db)
.await
.unwrap_or(vec![])
}