holy shit what the fuck am i doing

This commit is contained in:
Erin 2024-04-15 02:10:27 -04:00
commit 4b4122267a
Signed by: erin
SSH key fingerprint: SHA256:clvLPaxKthBet+VUQTKQdDkjaqg2/KnYHQaPASp5pFE
6 changed files with 3011 additions and 0 deletions

43
src/main.rs Normal file
View file

@ -0,0 +1,43 @@
use sqlx::SqlitePool;
use std::env;
#[rocket::launch]
async fn rocket() -> _ {
println!("Hello, world!");
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is required");
let pool = SqlitePool::connect(&db_url)
.await
.expect("Failed to connect to database");
rocket::build()
.manage(pool)
.mount("/", rocket::routes![index, add])
}
#[rocket::get("/")]
async fn index(pool: &rocket::State<SqlitePool>) -> String {
let records = sqlx::query!("SELECT id, name, content FROM comments")
.fetch_all(pool.inner())
.await
.expect("what the fuck");
let mut result = "yeetus\n".to_owned();
for rec in records {
result += &format!(
"- {}: {}\n",
rec.name.unwrap_or("anonymous".to_owned()),
rec.content
);
}
result
}
#[rocket::get("/add")]
async fn add(pool: &rocket::State<SqlitePool>) -> &str {
sqlx::query!("INSERT INTO comments (content) VALUES (\"hi\")")
.execute(pool.inner())
.await
.expect("ajkl;shfklshadflgksdfg");
"neat ok"
}