feat: conversion script
This commit is contained in:
parent
119a86b0ac
commit
f11fdb4dde
3 changed files with 185 additions and 0 deletions
38
src/lib.rs
38
src/lib.rs
|
@ -15,6 +15,7 @@ use sqlx::{
|
|||
Error, FromRow, Pool, Row, Sqlite,
|
||||
};
|
||||
use std::{env, str::FromStr, sync::Arc};
|
||||
use serenity::model::id::UserId;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
pub struct Config {
|
||||
|
@ -152,6 +153,32 @@ pub struct Wolves {
|
|||
pub minecraft: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct Wolves2 {
|
||||
pub id_wolves: String,
|
||||
pub email: String,
|
||||
pub discord: Option<UserId>,
|
||||
pub minecraft: Option<String>,
|
||||
}
|
||||
impl<'r> FromRow<'r, SqliteRow> for Wolves2 {
|
||||
fn from_row(row: &'r SqliteRow) -> Result<Self, Error> {
|
||||
let discord = match row.try_get("discord") {
|
||||
Ok(x) => {
|
||||
let tmp: i64 = x;
|
||||
Some(UserId::from(tmp as u64))
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
id_wolves: row.try_get("id_wolves")?,
|
||||
email: row.try_get("email")?,
|
||||
discord,
|
||||
minecraft: row.try_get("minecraft")?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, sqlx::FromRow)]
|
||||
pub struct WolvesVerify {
|
||||
pub email: String,
|
||||
|
@ -222,6 +249,17 @@ pub async fn db_init(config: &Config) -> Result<Pool<Sqlite>, Error> {
|
|||
.execute(&pool)
|
||||
.await?;
|
||||
|
||||
sqlx::query(
|
||||
"CREATE TABLE IF NOT EXISTS wolves2 (
|
||||
id_wolves text PRIMARY KEY,
|
||||
email text not null,
|
||||
discord integer,
|
||||
minecraft text
|
||||
)",
|
||||
)
|
||||
.execute(&pool)
|
||||
.await?;
|
||||
|
||||
sqlx::query("CREATE INDEX IF NOT EXISTS index_discord ON wolves (discord)").execute(&pool).await?;
|
||||
|
||||
sqlx::query(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue