proof_of_sql/base/database/
column_ref.rs

1use super::{ColumnType, TableRef};
2use serde::{Deserialize, Serialize};
3use sqlparser::ast::Ident;
4
5/// Reference of a SQL column
6#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)]
7pub struct ColumnRef {
8    column_id: Ident,
9    table_ref: TableRef,
10    column_type: ColumnType,
11}
12
13impl ColumnRef {
14    /// Create a new `ColumnRef` from a table, column identifier and column type
15    #[must_use]
16    pub fn new(table_ref: TableRef, column_id: Ident, column_type: ColumnType) -> Self {
17        Self {
18            column_id,
19            table_ref,
20            column_type,
21        }
22    }
23
24    /// Returns the table reference of this column
25    #[must_use]
26    pub fn table_ref(&self) -> TableRef {
27        self.table_ref.clone()
28    }
29
30    /// Returns the column identifier of this column
31    #[must_use]
32    pub fn column_id(&self) -> Ident {
33        self.column_id.clone()
34    }
35
36    /// Returns the column type of this column
37    #[must_use]
38    pub fn column_type(&self) -> &ColumnType {
39        &self.column_type
40    }
41}