diff --git a/.sqlx/query-f17495d023bac377869af665478b21bb962599df4bf7f59dd8336dc538f5a8fb.json b/.sqlx/query-a49c11570aff702c2e583a7e37a94fcb98c3a76db228002b01a93e74a747c44a.json similarity index 55% rename from .sqlx/query-f17495d023bac377869af665478b21bb962599df4bf7f59dd8336dc538f5a8fb.json rename to .sqlx/query-a49c11570aff702c2e583a7e37a94fcb98c3a76db228002b01a93e74a747c44a.json index c9fbd99..fb3f82b 100644 --- a/.sqlx/query-f17495d023bac377869af665478b21bb962599df4bf7f59dd8336dc538f5a8fb.json +++ b/.sqlx/query-a49c11570aff702c2e583a7e37a94fcb98c3a76db228002b01a93e74a747c44a.json @@ -1,6 +1,6 @@ { "db_name": "SQLite", - "query": "SELECT pronouns \n FROM pronouns \n WHERE username == ?", + "query": "SELECT pronouns \n FROM pronouns \n WHERE username == ?", "describe": { "columns": [ { @@ -16,5 +16,5 @@ false ] }, - "hash": "f17495d023bac377869af665478b21bb962599df4bf7f59dd8336dc538f5a8fb" + "hash": "a49c11570aff702c2e583a7e37a94fcb98c3a76db228002b01a93e74a747c44a" } diff --git a/src/main.rs b/src/main.rs index af6fdb5..b76c68f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,27 +9,6 @@ use rand::{ thread_rng, seq::IteratorRandom }; use sqlx::{SqlitePool, sqlite::SqlitePoolOptions}; -async fn user_pronouns( - State(pool): State, - Path(user): Path, - ) -> Result { - let res = sqlx::query!("SELECT pronouns - FROM pronouns - WHERE username == ?", - user) - .fetch_one(&pool) - .await - .map_err(|err| match err { - sqlx::Error::RowNotFound => StatusCode::NOT_FOUND, - _ => StatusCode::INTERNAL_SERVER_ERROR - })?; - res.pronouns - .split(';') - .choose(&mut thread_rng()) - .map(ToOwned::to_owned) - .ok_or(StatusCode::NOT_FOUND) -} - #[tokio::main] async fn main() { let pool = SqlitePoolOptions::new() @@ -52,3 +31,25 @@ async fn main() { .await .unwrap(); } + + +async fn user_pronouns( + State(pool): State, + Path(user): Path, + ) -> Result { + sqlx::query!("SELECT pronouns + FROM pronouns + WHERE username == ?", + user) + .fetch_one(&pool) + .await + .map_err(|err| match err { + sqlx::Error::RowNotFound => StatusCode::NOT_FOUND, + _ => StatusCode::INTERNAL_SERVER_ERROR + })? + .pronouns + .split(';') + .choose(&mut thread_rng()) + .map(ToOwned::to_owned) + .ok_or(StatusCode::NOT_FOUND) +}