This commit is contained in:
Artémis 2025-01-10 16:04:31 +01:00
parent 63d78a1772
commit 937797f5b7
7 changed files with 1167 additions and 35 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
# built binary
cap
/target
*.sqlite

1143
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -6,3 +6,5 @@ edition = "2021"
[dependencies]
rocket = "0.5.1"
rocket_dyn_templates = { version = "0.2.0", features = ["tera"] }
rocket_db_pools = { version = "0.2.0", features = ["sqlx_sqlite"] }
sqlx = { version = "0.7", default-features = false, features = ["sqlite", "macros", "chrono"] }

2
Rocket.toml Normal file
View file

@ -0,0 +1,2 @@
[default.databases.dolltags]
url = "dolltags.sqlite"

View file

@ -2,28 +2,25 @@
-- notnulls are tmp till i deal with proper validation
create table doll_profiles (
id uuid not null primary key,
public_id char(6) not null, -- 000000 format
created_at timestamptz not null default current_timestamp,
updated_at timestamptz,
id integer not null primary key, -- 000000 format
created_at text not null default current_timestamp,
updated_at text,
-- base info
name varchar(255) not null,
pronouns varchar(255) not null, -- format as `{subject}/{object}/{possessive}` eg `she/her/hers`
name text not null,
pronouns text not null, -- format as `{subject}/{object}/{possessive}` eg `she/her/hers`
handler_name text not null,
handler_url text not null,
-- customisation options for various entities
description text not null,
kind varchar(255) not null,
breed varchar(255) not null,
chassis_type varchar(255) not null,
chassis_id varchar(255) not null,
chassis_color varchar(255) not null,
kind text not null,
breed text not null,
chassis_type text not null,
chassis_id text not null,
chassis_color text not null,
-- ID'ing
behaviour varchar(255) not null,
microchipped boolean not null,
unique (public_id)
);
behaviour text not null,
microchipped integer not null
) strict;

View file

@ -8,6 +8,8 @@ pkgs.mkShell {
rustfmt clippy rust-analyzer
# native dependencies
# pkg-config
# Dev env
sqlite sqlitebrowser sqlx-cli
]
);
@ -17,4 +19,5 @@ pkgs.mkShell {
# Rust
# See https://discourse.nixos.org/t/rust-src-not-found-and-other-misadventures-of-developing-rust-on-nixos/11570/3?u=samuela. for more details.
RUST_SRC_PATH = pkgs.rust.packages.stable.rustPlatform.rustLibSrc;
DATABASE_URL = "sqlite://dolltags.sqlite";
}

View file

@ -2,7 +2,13 @@
extern crate rocket;
use rocket::form::Form;
use rocket::fs::{relative, FileServer};
use rocket_db_pools::{sqlx, Connection, Database};
use rocket_dyn_templates::{context, Template};
use sqlx::types::chrono;
#[derive(Database)]
#[database("dolltags")]
struct DollTags(sqlx::SqlitePool);
#[get("/")]
fn index() -> Template {
@ -39,7 +45,20 @@ fn handle_register(tag: Form<TagForm>) -> Template {
}
#[get("/profile?<ident>")]
fn show_profile(ident: &str) -> Template {
async fn show_profile(mut db: Connection<DollTags>, ident: &str) -> Template {
#[derive(Debug)]
struct Tag {
pub id: i64,
pub created_at: chrono::NaiveDateTime,
}
sqlx::query_as!(
Tag,
r#"select id, created_at as "created_at!: chrono::NaiveDateTime" from doll_profiles"#
)
.fetch_one(&mut **db)
.await
.expect("fuck");
Template::render(
"show_profile",
context! {
@ -52,6 +71,7 @@ fn show_profile(ident: &str) -> Template {
fn rocket() -> _ {
rocket::build()
.attach(Template::fairing())
.attach(DollTags::init())
.mount("/assets", FileServer::from(relative!("/assets")))
.mount(
"/",