holy shit what the fuck am i doing
This commit is contained in:
commit
4b4122267a
6 changed files with 3011 additions and 0 deletions
43
src/main.rs
Normal file
43
src/main.rs
Normal 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"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue