Skip to content

Commit

Permalink
IntoColumnDef SeaQL/sea-orm#2084
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Jan 28, 2024
1 parent 0dda132 commit eb16354
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/table/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ pub enum TableOpt {
CharacterSet(String),
}

pub trait IntoColumnDef {
fn into_column_def(self) -> ColumnDef;
}

/// All available table partition options
#[derive(Debug, Clone)]
pub enum TablePartition {}
Expand Down Expand Up @@ -136,8 +140,8 @@ impl TableCreateStatement {
}

/// Add a new table column
pub fn col(&mut self, column: &mut ColumnDef) -> &mut Self {
let mut column = column.take();
pub fn col<C: IntoColumnDef>(&mut self, column: C) -> &mut Self {
let mut column = column.into_column_def();
column.table = self.table.clone();
self.columns.push(column);
self
Expand Down Expand Up @@ -371,3 +375,15 @@ impl SchemaStatementBuilder for TableCreateStatement {

pub fn to_string<T: SchemaBuilder>(&self, schema_builder: T) -> String;
}

impl IntoColumnDef for &mut ColumnDef {
fn into_column_def(self) -> ColumnDef {
self.take()
}
}

impl IntoColumnDef for ColumnDef {
fn into_column_def(self) -> ColumnDef {
self
}
}

0 comments on commit eb16354

Please sign in to comment.