MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / column_def_from_entity_column

Function column_def_from_entity_column

src/schema/entity.rs:190–230  ·  view source on GitHub ↗
(column: E::Column, backend: DbBackend)

Source from the content-addressed store, hash-verified

188}
189
190fn column_def_from_entity_column<E>(column: E::Column, backend: DbBackend) -> ColumnDef
191where
192 E: EntityTrait,
193{
194 let orm_column_def = column.def();
195 let types = match &orm_column_def.col_type {
196 ColumnType::Enum { name, variants } => match backend {
197 DbBackend::MySql => {
198 let variants: Vec<String> = variants.iter().map(|v| v.to_string()).collect();
199 ColumnType::custom(format!("ENUM('{}')", variants.join("', '")).as_str())
200 }
201 DbBackend::Postgres => ColumnType::Custom(SeaRc::clone(name)),
202 DbBackend::Sqlite => orm_column_def.col_type,
203 },
204 _ => orm_column_def.col_type,
205 };
206 let mut column_def = ColumnDef::new_with_type(column, types);
207 if !orm_column_def.null {
208 column_def.not_null();
209 }
210 if orm_column_def.unique {
211 column_def.unique_key();
212 }
213 if let Some(default) = orm_column_def.default {
214 column_def.default(default);
215 }
216 if let Some(comment) = orm_column_def.comment {
217 column_def.comment(comment);
218 }
219 for primary_key in E::PrimaryKey::iter() {
220 if column.to_string() == primary_key.into_column().to_string() {
221 if E::PrimaryKey::auto_increment() {
222 column_def.auto_increment();
223 }
224 if <<E::PrimaryKey as PrimaryKeyTrait>::ValueType as PrimaryKeyArity>::ARITY == 1 {
225 column_def.primary_key();
226 }
227 }
228 }
229 column_def
230}
231
232#[cfg(test)]
233mod tests {

Callers

nothing calls this directly

Calls 6

customFunction · 0.85
defMethod · 0.45
as_strMethod · 0.45
defaultMethod · 0.45
commentMethod · 0.45
auto_incrementMethod · 0.45

Tested by

no test coverage detected