taos_query/helpers/
topic.rs

1use chrono::{DateTime, Local};
2
3use serde::{Deserialize, Serialize};
4
5/// Information for `show topics` record.
6#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
7pub struct Topic {
8    topic_name: String,
9    db_name: String,
10    create_time: DateTime<Local>,
11    sql: String,
12}
13
14impl Topic {
15    /// Topic name.
16    pub fn name(&self) -> &str {
17        &self.topic_name
18    }
19
20    /// Database name of the topic.
21    pub fn db_name(&self) -> &str {
22        &self.db_name
23    }
24
25    /// Created time of the topic
26    pub fn create_time(&self) -> &DateTime<Local> {
27        &self.create_time
28    }
29
30    /// The create sql for the topic
31    pub fn sql(&self) -> &str {
32        &self.sql
33    }
34
35    /// Check if the topic is a database-scope topic, otherwise is table-scope topic.
36    pub fn is_db_topic(&self) -> bool {
37        self.sql.contains("as database")
38    }
39
40    pub fn is_stable_topic(&self) -> bool {
41        self.sql.contains("as stable")
42    }
43}