surrealcs_kernel/logging/messages/transactions/
id.rs1pub fn create_id(connection_index: usize, transaction_index: usize) -> String {
13 let timestamp = chrono::Utc::now().timestamp().to_string();
14 format!("{}-{}-{}", connection_index, transaction_index, timestamp)
15}
16
17pub fn get_connection_index(id: &str) -> usize {
25 let parts: Vec<&str> = id.split("-").collect();
26 parts[0].parse::<usize>().unwrap()
27}
28
29pub fn get_transaction_index(id: &str) -> usize {
37 let parts: Vec<&str> = id.split("-").collect();
38 parts[1].parse::<usize>().unwrap()
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_create_id() {
47 let id = create_id(1, 1);
48 assert_eq!(id.len(), 14);
49 assert!(id.contains("1-1-"));
50 }
51
52 #[test]
53 fn test_get_connection_index() {
54 let id = create_id(1, 2);
55 let index = get_connection_index(&id);
56 assert_eq!(index, 1);
57 }
58
59 #[test]
60 fn test_get_transaction_index() {
61 let id = create_id(1, 2);
62 let index = get_transaction_index(&id);
63 assert_eq!(index, 2);
64 }
65}