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

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
*.sqlite*
.env
# Added by cargo
/target

View file

@ -0,0 +1,32 @@
{
"db_name": "SQLite",
"query": "SELECT id, name, content FROM comments",
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Int64"
},
{
"name": "name",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "content",
"ordinal": 2,
"type_info": "Text"
}
],
"parameters": {
"Right": 0
},
"nullable": [
false,
true,
false
]
},
"hash": "028ae30edade84a65cc41385416f2233cc74bbaeececa1cf4ff097a9adcbe701"
}

2912
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

12
Cargo.toml Normal file
View file

@ -0,0 +1,12 @@
[package]
name = "comments"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.82"
async-std = { version = "1.12.0", features = ["attributes"] }
rocket = "0.5.0"
sqlx = { version = "0.7", features = ["runtime-async-std", "sqlite", "migrate"] }

View file

@ -0,0 +1,6 @@
CREATE TABLE IF NOT EXISTS comments
(
id INTEGER PRIMARY KEY NOT NULL,
name TEXT,
content TEXT NOT NULL
);

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"
}