Struct Schema
pub struct Schema { /* private fields */ }Expand description
This is a helper struct to convert EntityTrait
into different sea_query statements.
Implementations§
§impl Schema
impl Schema
pub fn create_enum_from_active_enum<A>(&self) -> Option<TypeCreateStatement>where
A: ActiveEnum,
pub fn create_enum_from_active_enum<A>(&self) -> Option<TypeCreateStatement>where
A: ActiveEnum,
Creates Postgres enums from an ActiveEnum. See TypeCreateStatement for more details.
Returns None if not Postgres.
pub fn create_enum_from_entity<E>(&self, entity: E) -> Vec<TypeCreateStatement>where
E: EntityTrait,
pub fn create_enum_from_entity<E>(&self, entity: E) -> Vec<TypeCreateStatement>where
E: EntityTrait,
Creates Postgres enums from an Entity. See TypeCreateStatement for more details.
Returns empty vec if not Postgres.
pub fn create_table_from_entity<E>(&self, entity: E) -> TableCreateStatementwhere
E: EntityTrait,
pub fn create_table_from_entity<E>(&self, entity: E) -> TableCreateStatementwhere
E: EntityTrait,
Creates a table from an Entity. See TableCreateStatement for more details.
pub fn create_index_from_entity<E>(
&self,
entity: E,
) -> Vec<IndexCreateStatement>where
E: EntityTrait,
pub fn create_index_from_entity<E>(
&self,
entity: E,
) -> Vec<IndexCreateStatement>where
E: EntityTrait,
Creates the indexes from an Entity, returning an empty Vec if there are none to create. See IndexCreateStatement for more details
pub fn get_column_def<E>(&self, column: E::Column) -> ColumnDefwhere
E: EntityTrait,
pub fn get_column_def<E>(&self, column: E::Column) -> ColumnDefwhere
E: EntityTrait,
Creates a column definition for example to update a table.
use sea_orm::sea_query::TableAlterStatement;
use sea_orm::{DbBackend, Schema, Statement};
mod post {
use sea_orm::entity::prelude::*;
#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "posts")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: u32,
pub title: String,
}
impl ActiveModelBehavior for ActiveModel {}
}
let schema = Schema::new(DbBackend::MySql);
let alter_table: Statement = DbBackend::MySql.build(
TableAlterStatement::new()
.table(post::Entity)
.add_column(&mut schema.get_column_def::<post::Entity>(post::Column::Title)),
);
assert_eq!(
alter_table.to_string(),
"ALTER TABLE `posts` ADD COLUMN `title` varchar(255) NOT NULL"
);§impl Schema
impl Schema
pub fn json_schema_from_entity<E>(&self, entity: E) -> Valuewhere
E: EntityTrait,
pub fn json_schema_from_entity<E>(&self, entity: E) -> Valuewhere
E: EntityTrait,
Construct a schema description in json for the given Entity.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Schema
impl RefUnwindSafe for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnwindSafe for Schema
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more