Skip to main content

arrow_sql_server/mssql/
column.rs

1//! MSSQL column metadata model.
2
3use super::{Identifier, MssqlType};
4
5/// MSSQL column metadata used by a schema mapping.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct MssqlColumn {
8    name: Identifier,
9    ty: MssqlType,
10    nullable: bool,
11}
12
13impl MssqlColumn {
14    /// Creates MSSQL column metadata.
15    pub const fn new(name: Identifier, ty: MssqlType, nullable: bool) -> Self {
16        Self { name, ty, nullable }
17    }
18
19    /// Returns the column name.
20    pub const fn name(&self) -> &Identifier {
21        &self.name
22    }
23
24    /// Returns the MSSQL column type.
25    pub const fn ty(&self) -> &MssqlType {
26        &self.ty
27    }
28
29    /// Returns true when the column allows `NULL`.
30    pub const fn nullable(&self) -> bool {
31        self.nullable
32    }
33
34    pub(crate) fn to_sql(&self) -> String {
35        let nullability = if self.nullable { "NULL" } else { "NOT NULL" };
36        format!(
37            "{} {} {nullability}",
38            self.name.quoted_sql(),
39            self.ty.to_sql()
40        )
41    }
42}