1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use chrono::{DateTime, Local};

use serde::{Deserialize, Serialize};

/// Information for `show topics` record.
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Topic {
    topic_name: String,
    db_name: String,
    create_time: DateTime<Local>,
    sql: String,
}

impl Topic {
    /// Topic name.
    pub fn name(&self) -> &str {
        &self.topic_name
    }

    /// Database name of the topic.
    pub fn db_name(&self) -> &str {
        &self.db_name
    }

    /// Created time of the topic
    pub fn create_time(&self) -> &DateTime<Local> {
        &self.create_time
    }

    /// The create sql for the topic
    pub fn sql(&self) -> &str {
        &self.sql
    }

    /// Check if the topic is a database-scope topic, otherwise is table-scope topic.
    pub fn is_db_topic(&self) -> bool {
        self.sql.contains("as database")
    }

    pub fn is_stable_topic(&self) -> bool {
        self.sql.contains("as stable")
    }
}