Skip to main content

Column

Struct Column 

Source
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: bool

NOT 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

Source

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.

Source

pub const fn not_null(self) -> Self

Adds NOT NULL.

Source

pub fn default_value(self, value: impl Into<Cow<'static, str>>) -> Self

Sets the DEFAULT value, written as SQL.

Source

pub fn identity(self, identity: Identity) -> Self

Makes the column an identity column.

Source

pub fn comment(self, comment: impl Into<Cow<'static, str>>) -> Self

Sets the column comment.

Source

pub fn schema(&self) -> &str

Returns the schema name.

Source

pub fn table(&self) -> &str

Returns the table name.

Source

pub fn name(&self) -> &str

Returns the column name.

Source

pub fn sql_type(&self) -> &str

Returns the SQL type.

Source§

impl Column

Source

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.

Source

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.

Source

pub fn add_column_sql(&self) -> String

Renders ALTER TABLE ... ADD COLUMN ...;.

Source

pub fn drop_column_sql(&self) -> String

Renders ALTER TABLE ... DROP COLUMN ...;.

Trait Implementations§

Source§

impl Clone for Column

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Column

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Column

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Column

Source§

impl From<ColumnDef> for Column

Source§

fn from(def: ColumnDef) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Column

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Column

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.