diff --git a/tracing-surreal/src/stop.rs b/tracing-surreal/src/stop.rs index 1cd830a..84c8b2a 100644 --- a/tracing-surreal/src/stop.rs +++ b/tracing-surreal/src/stop.rs @@ -241,7 +241,7 @@ impl Stop { }) } - pub async fn query_last_n(&self, n: u8) -> Result, surrealdb::Error> { + pub async fn query_last_n(&self, n: u8) -> Result, surrealdb::Error> { #[derive(Serialize)] struct Bind { table_name: String, @@ -250,14 +250,21 @@ impl Stop { let table_name = format!("{}-msg", self.formatted_timestamp); + #[derive(Deserialize)] + struct ClientInfo { + c_client_name: String, + } + #[derive(Deserialize)] struct Msg { message: String, + client_id: ClientInfo, } // last_id: 01JH8CBYAKFSRK8Y9HY02QVTDS // SELECT * FROM (SELECT *, client_id[*] FROM type::thing($table_name, ..=$last_id) ORDER BY id DESC LIMIT $n) ORDER BY id - let query = "SELECT * FROM type::thing($table_name, ..) ORDER BY id DESC LIMIT $n"; + let query = + "SELECT *, client_id[*] FROM type::thing($table_name, ..) ORDER BY id DESC LIMIT $n"; let msgs: Vec = self .db .query(query) @@ -267,7 +274,11 @@ impl Stop { // clients + disconnects & merge - Ok(msgs.iter().rev().map(|m| m.message.clone()).collect()) + Ok(msgs + .iter() + .rev() + .map(|m| (m.message.clone(), m.client_id.c_client_name.clone())) + .collect()) } pub async fn print(&self) {