toasty_sql/stmt/
column_def.rs

1use toasty_core::{
2    driver,
3    schema::db::{self, Column},
4};
5
6/// A column definition used in `CREATE TABLE` and `ADD COLUMN` statements.
7#[derive(Debug, Clone)]
8pub struct ColumnDef {
9    /// Column name.
10    pub name: String,
11    /// Storage type (e.g. `INTEGER`, `TEXT`).
12    pub ty: db::Type,
13    /// When `true`, the column has a `NOT NULL` constraint.
14    pub not_null: bool,
15    /// When `true`, the column auto-increments.
16    pub auto_increment: bool,
17}
18
19impl ColumnDef {
20    pub(crate) fn from_schema(column: &Column, _storage_types: &driver::StorageTypes) -> Self {
21        Self {
22            name: column.name.clone(),
23            ty: column.storage_ty.clone(),
24            not_null: !column.nullable,
25            auto_increment: column.auto_increment,
26        }
27    }
28}