sea_schema/postgres/def/column.rs
1#[cfg(feature = "with-serde")]
2use serde::{Deserialize, Serialize};
3
4use super::{NotNull, Type};
5
6#[derive(Clone, Debug, PartialEq)]
7#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
8pub struct ColumnInfo {
9 /// The name of the column
10 pub name: String,
11 /// The type of the column with any additional definitions such as the precision or the character
12 /// set
13 pub col_type: ColumnType,
14 /// The default value experssion for this column, if any
15 pub default: Option<ColumnExpression>,
16 /// The generation expression for this column, if it is a generated colum
17 pub generated: Option<ColumnExpression>,
18 pub not_null: Option<NotNull>,
19 pub is_identity: bool,
20 // TODO:
21 // /// A constraint that ensures the value of a column is unique among all other rows in the table
22 // pub unique: Option<Vec<constraints::Unique>>,
23 // /// A constraint that states that the column is the unique identifier or part of the unique
24 // /// identifier of each row for this table
25 // pub primary_key: Option<constraints::PrimaryKey>,
26 // /// A constraint that ensures that the value of this column must refer to a unique key in another
27 // /// table
28 // pub references: Option<constraints::References>,
29
30 // FIXME: Include if there's a convenient way to look for this
31 // /// Comments on the column made by the user
32 // pub comment: String,
33}
34
35pub type ColumnType = Type;
36
37#[derive(Clone, Debug, PartialEq)]
38#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
39pub struct ColumnExpression(pub String);
40
41impl ColumnExpression {
42 pub fn from_option_string(maybe_string: Option<String>) -> Option<ColumnExpression> {
43 maybe_string.map(ColumnExpression)
44 }
45}