//! Per-page persistence. Mirrors the rows that `pages` holds. use sqlx::PgPool; use uuid::Uuid; use crate::domain::Page; use crate::error::AppResult; pub async fn create( pool: &PgPool, chapter_id: Uuid, page_number: i32, storage_key: &str, content_type: &str, ) -> AppResult { let row = sqlx::query_as::<_, Page>( r#" INSERT INTO pages (chapter_id, page_number, storage_key, content_type) VALUES ($1, $2, $3, $4) RETURNING id, chapter_id, page_number, storage_key, content_type "#, ) .bind(chapter_id) .bind(page_number) .bind(storage_key) .bind(content_type) .fetch_one(pool) .await?; Ok(row) } pub async fn list_for_chapter(pool: &PgPool, chapter_id: Uuid) -> AppResult> { let rows = sqlx::query_as::<_, Page>( r#" SELECT id, chapter_id, page_number, storage_key, content_type FROM pages WHERE chapter_id = $1 ORDER BY page_number ASC "#, ) .bind(chapter_id) .fetch_all(pool) .await?; Ok(rows) }