pub struct Column {Show 13 fields
pub schema: Cow<'static, str>,
pub table: Cow<'static, str>,
pub name: Cow<'static, str>,
pub sql_type: Cow<'static, str>,
pub type_schema: Option<Cow<'static, str>>,
pub not_null: bool,
pub default: Option<Cow<'static, str>>,
pub generated: Option<Generated>,
pub identity: Option<Identity>,
pub dimensions: Option<i32>,
pub comment: Option<Cow<'static, str>>,
pub collate: Option<Cow<'static, str>>,
pub ordinal_position: Option<i32>,
}Expand description
A table column, as stored in migration snapshots.
Fields§
§schema: Cow<'static, str>Schema name
table: Cow<'static, str>Parent table name
name: Cow<'static, str>Column name
sql_type: Cow<'static, str>SQL type, such as "integer" (serialized as type)
type_schema: Option<Cow<'static, str>>Schema of a custom or enum type
not_null: boolNOT NULL
default: Option<Cow<'static, str>>DEFAULT value as SQL
generated: Option<Generated>Generated column configuration
identity: Option<Identity>Identity column configuration
dimensions: Option<i32>Number of array dimensions
comment: Option<Cow<'static, str>>Column comment, emitted as COMMENT ON COLUMN
collate: Option<Cow<'static, str>>Collation name (e.g. "en_US", "C"). None means the database
default collation and no COLLATE clause is emitted.
ordinal_position: Option<i32>Ordinal position within the table (1-based).
This is primarily populated by introspection and used for stable codegen ordering.
Implementations§
Source§impl Column
impl Column
Sourcepub fn new(
schema: impl Into<Cow<'static, str>>,
table: impl Into<Cow<'static, str>>,
name: impl Into<Cow<'static, str>>,
sql_type: impl Into<Cow<'static, str>>,
) -> Self
pub fn new( schema: impl Into<Cow<'static, str>>, table: impl Into<Cow<'static, str>>, name: impl Into<Cow<'static, str>>, sql_type: impl Into<Cow<'static, str>>, ) -> Self
Creates a nullable column with no default.
Sourcepub fn default_value(self, value: impl Into<Cow<'static, str>>) -> Self
pub fn default_value(self, value: impl Into<Cow<'static, str>>) -> Self
Sets the DEFAULT value, written as SQL.
Source§impl Column
impl Column
Sourcepub fn type_sql(&self) -> String
pub fn type_sql(&self) -> String
Renders the column’s type.
Built-in types render verbatim (integer, varchar(255)). When
type_schema names a non-public schema, the custom/enum type name
is quoted and schema-qualified ("app"."status"). For public the
schema is elided and the name is only quoted when it needs it (mixed
case or other non-lowercase characters), so ordinary lowercase enum
names keep rendering exactly as before. Parenthesized type parameters
stay outside the quotes; array dimensions are appended.
Sourcepub fn to_column_sql(&self) -> String
pub fn to_column_sql(&self) -> String
Renders the column definition as used inside CREATE TABLE, such as
"name" text NOT NULL.
DEFAULT is left out on identity and generated columns, which
PostgreSQL does not allow to have one.
Sourcepub fn add_column_sql(&self) -> String
pub fn add_column_sql(&self) -> String
Renders ALTER TABLE ... ADD COLUMN ...;.
Sourcepub fn drop_column_sql(&self) -> String
pub fn drop_column_sql(&self) -> String
Renders ALTER TABLE ... DROP COLUMN ...;.