a bit of bonus; very funny that the endpoint is just one long chained statement now

main
znpra 1 year ago
parent e321b79b5c
commit 5198090d70

@ -1,6 +1,6 @@
{ {
"db_name": "SQLite", "db_name": "SQLite",
"query": "SELECT pronouns \n FROM pronouns \n WHERE username == ?", "query": "SELECT pronouns \n FROM pronouns \n WHERE username == ?",
"describe": { "describe": {
"columns": [ "columns": [
{ {
@ -16,5 +16,5 @@
false false
] ]
}, },
"hash": "f17495d023bac377869af665478b21bb962599df4bf7f59dd8336dc538f5a8fb" "hash": "a49c11570aff702c2e583a7e37a94fcb98c3a76db228002b01a93e74a747c44a"
} }

@ -9,27 +9,6 @@ use rand::{ thread_rng, seq::IteratorRandom };
use sqlx::{SqlitePool, sqlite::SqlitePoolOptions}; use sqlx::{SqlitePool, sqlite::SqlitePoolOptions};
async fn user_pronouns(
State(pool): State<SqlitePool>,
Path(user): Path<String>,
) -> Result<String, StatusCode> {
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] #[tokio::main]
async fn main() { async fn main() {
let pool = SqlitePoolOptions::new() let pool = SqlitePoolOptions::new()
@ -52,3 +31,25 @@ async fn main() {
.await .await
.unwrap(); .unwrap();
} }
async fn user_pronouns(
State(pool): State<SqlitePool>,
Path(user): Path<String>,
) -> Result<String, StatusCode> {
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)
}

Loading…
Cancel
Save