diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2024-01-16 22:18:32 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2024-01-16 22:18:32 +0100 |
commit | 81a61c28619ef9f32e79e5698bc4162ca1ceb82d (patch) | |
tree | d274a43a7b05a0a48269af1f32f616951b0c4288 /src/db.rs | |
parent | 6db211a70f95c339710ac73ec12d9e7c5664a278 (diff) | |
download | cats-radio-node-81a61c28619ef9f32e79e5698bc4162ca1ceb82d.tar.gz cats-radio-node-81a61c28619ef9f32e79e5698bc4162ca1ceb82d.tar.bz2 cats-radio-node-81a61c28619ef9f32e79e5698bc4162ca1ceb82d.zip |
Add Destination to Send page
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -5,7 +5,8 @@ use sqlx::SqlitePool; #[derive(Clone)] pub struct Database { - pool : SqlitePool + pool : SqlitePool, + num_frames_received : u64, } #[derive(sqlx::FromRow, Debug)] @@ -25,7 +26,16 @@ impl Database { .await .expect("could not run SQLx migrations"); - Self { pool } + let num_frames_received : i64 = sqlx::query_scalar(r#"SELECT COUNT(id) FROM frames_received"#) + .fetch_one(&pool) + .await + .expect("could not count frames"); + + Self { pool, num_frames_received: num_frames_received.try_into().unwrap() } + } + + pub fn get_num_received_frames(&self) -> u64 { + self.num_frames_received } pub async fn store_packet(&mut self, packet: &[u8]) -> anyhow::Result<()> { @@ -41,6 +51,8 @@ impl Database { .await? .last_insert_rowid(); + self.num_frames_received += 1; + debug!("INSERTed row {id}"); Ok(()) } |