From aad60a57521dd9deb10647d93c8bf11f660722d2 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Thu, 28 Mar 2024 22:16:18 -0700 Subject: [PATCH] Make the sample javascript first register the hit, then fetch the count. --- index.html | 12 +++++------- src/main.rs | 7 ++++++- user/index.html | 10 ++++------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/index.html b/index.html index e328fe7..e087617 100644 --- a/index.html +++ b/index.html @@ -7,20 +7,18 @@ - -

+

There have been no views of this page

user

- + diff --git a/src/main.rs b/src/main.rs index 8760dd7..67900ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,7 +83,12 @@ async fn register_hit( tx.commit().await.unwrap_or_default(); } - "".to_string() + let hits = sqlx::query_scalar!("select count(*) from hits where page = ?", slug) + .fetch_one(&db) + .await + .unwrap_or(1); + + format!("{hits}") } #[axum::debug_handler] diff --git a/user/index.html b/user/index.html index b1efa83..421ee5a 100644 --- a/user/index.html +++ b/user/index.html @@ -7,19 +7,17 @@ - -

+

oy, guv, there've been no hits, mate.

- +