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
use std::rc::Rc;
use crate::types::*;

/// Specification of a table index
#[derive(Debug, Clone)]
pub struct TableIndex {
    pub(crate) name: Option<String>,
    pub(crate) columns: Vec<Rc<dyn Iden>>,
}

impl Default for TableIndex {
    fn default() -> Self {
        Self::new()
    }
}

impl TableIndex {
    /// Construct a new table index
    pub fn new() -> Self {
        Self {
            name: None,
            columns: Vec::new(),
        }
    }

    /// Set index name
    pub fn name(&mut self, name: &str) -> &mut Self {
        self.name = Some(name.into());
        self
    }

    /// Set index column
    pub fn col<T: 'static>(&mut self, column: T) -> &mut Self
        where T: Iden {
        self.columns.push(Rc::new(column));
        self
    }
}