Better database layout with uuid primary keys

Serialize and deserialize the uuid ids as base62 strings in the URLs.
This commit is contained in:
2023-06-27 14:03:52 -04:00
parent 4e41bbd6e1
commit abd540d2ff
17 changed files with 290 additions and 121 deletions

View File

@@ -1,4 +1,4 @@
use axum::extract::{State, Path};
use axum::extract::{Path, State};
use axum::response::Response;
use maud::{html, PreEscaped};
use sqlx::PgPool;
@@ -6,9 +6,14 @@ use sqlx::PgPool;
use crate::error::Result;
use crate::models::entry::get_entry;
use crate::partials::layout::Layout;
use crate::uuid::Base62Uuid;
pub async fn get(Path(id): Path<i32>, State(pool): State<PgPool>, layout: Layout) -> Result<Response> {
let entry = get_entry(&pool, id).await?;
pub async fn get(
Path(id): Path<Base62Uuid>,
State(pool): State<PgPool>,
layout: Layout,
) -> Result<Response> {
let entry = get_entry(&pool, id.as_uuid()).await?;
Ok(layout.render(html! {
@let title = entry.title.unwrap_or_else(|| "Untitled".to_string());
h1 { a href=(entry.url) { (title) } }