database_reflection/reflection/
index.rs

1use crate::reflection::column::Column;
2use serde::{Deserialize, Serialize};
3use std::sync::Arc;
4
5#[derive(Clone, Debug, Serialize, Deserialize)]
6pub struct Index {
7    name: Arc<String>,
8    column: Arc<Column>,
9    primary: bool,
10    unique: bool,
11}
12
13impl Index {
14    /// Create an index
15    pub fn new(name: impl ToString, column: Arc<Column>, primary: bool, unique: bool) -> Self {
16        Index {
17            name: Arc::new(name.to_string()),
18            column,
19            primary,
20            unique,
21        }
22    }
23
24    /// Get index name
25    pub fn name(&self) -> Arc<String> {
26        self.name.clone()
27    }
28
29    /// Get column
30    pub fn column(&self) -> &Column {
31        &self.column
32    }
33
34    /// Get flag indicating whether the index is a primary key
35    pub fn primary(&self) -> bool {
36        self.primary
37    }
38
39    /// Get a flag indicating whether the index is unique
40    pub fn unique(&self) -> bool {
41        self.unique
42    }
43}