From eb163549c076fde4c129864468e003ee2ccd1886 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Sun, 28 Jan 2024 19:23:35 +0000 Subject: [PATCH] IntoColumnDef https://github.com/SeaQL/sea-orm/issues/2084 --- src/table/create.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/table/create.rs b/src/table/create.rs index 77739f98..5269fe3c 100644 --- a/src/table/create.rs +++ b/src/table/create.rs @@ -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 {} @@ -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(&mut self, column: C) -> &mut Self { + let mut column = column.into_column_def(); column.table = self.table.clone(); self.columns.push(column); self @@ -371,3 +375,15 @@ impl SchemaStatementBuilder for TableCreateStatement { pub fn to_string(&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 + } +}