pub struct ColumnDef {
pub schema: &'static str,
pub table: &'static str,
pub name: &'static str,
pub sql_type: &'static str,
pub type_schema: Option<&'static str>,
pub not_null: bool,
pub default: Option<&'static str>,
pub generated: Option<GeneratedDef>,
pub identity: Option<IdentityDef>,
pub dimensions: Option<i32>,
pub comment: Option<&'static str>,
pub collate: Option<&'static str>,
}Expand description
A column definition that can be built in a const.
Primary keys and unique constraints are separate entities
(PrimaryKeyDef,
UniqueConstraintDef).
§Examples
use drizzle_types::postgres::ddl::{ColumnDef, IdentityDef, IdentityType};
const ID: ColumnDef = ColumnDef::new("public", "users", "id", "integer")
.not_null()
.identity(IdentityDef::new("users_id_seq", IdentityType::Always));
let column = ID.into_column();
assert!(column.identity.is_some());Fields§
§schema: &'static strSchema name
table: &'static strParent table name
name: &'static strColumn name
sql_type: &'static strSQL type, such as "integer" or "varchar(255)"; for an enum, the
enum’s type name
type_schema: Option<&'static str>Schema of a custom or enum type
not_null: boolNOT NULL
default: Option<&'static str>DEFAULT value as SQL
generated: Option<GeneratedDef>Generated column configuration
identity: Option<IdentityDef>Identity column configuration
dimensions: Option<i32>Number of array dimensions: Some(1) renders type[]
comment: Option<&'static str>Column comment, emitted as COMMENT ON COLUMN
collate: Option<&'static str>Collation name (e.g. "en_US", "C", "POSIX", or a custom
CREATE COLLATION name). None uses the type’s default collation and
emits no COLLATE clause.
Implementations§
Source§impl ColumnDef
impl ColumnDef
Sourcepub const fn new(
schema: &'static str,
table: &'static str,
name: &'static str,
sql_type: &'static str,
) -> Self
pub const fn new( schema: &'static str, table: &'static str, name: &'static str, sql_type: &'static str, ) -> Self
Creates a nullable column with no default.
Sourcepub const fn type_schema(self, schema: &'static str) -> Self
pub const fn type_schema(self, schema: &'static str) -> Self
Sets the schema of a custom or enum type.
Sourcepub const fn default_value(self, value: &'static str) -> Self
pub const fn default_value(self, value: &'static str) -> Self
Sets the DEFAULT value, written as SQL.
Sourcepub const fn generated_stored(self, expression: &'static str) -> Self
pub const fn generated_stored(self, expression: &'static str) -> Self
Makes the column GENERATED ALWAYS AS (expression) STORED.
Sourcepub const fn generated_virtual(self, expression: &'static str) -> Self
pub const fn generated_virtual(self, expression: &'static str) -> Self
Makes the column GENERATED ALWAYS AS (expression) VIRTUAL.
Sourcepub const fn identity(self, identity: IdentityDef) -> Self
pub const fn identity(self, identity: IdentityDef) -> Self
Makes the column an identity column.
Sourcepub const fn dimensions(self, dims: i32) -> Self
pub const fn dimensions(self, dims: i32) -> Self
Sets the number of array dimensions.
Sourcepub const fn collate(self, name: &'static str) -> Self
pub const fn collate(self, name: &'static str) -> Self
Sets the column’s collation.
Pass the bare name, such as en_US; it is rendered quoted, as in
COLLATE "en_US".
Sourcepub const fn into_column(self) -> Column
pub const fn into_column(self) -> Column
Converts to the runtime Column.