Skip to content

Commit

Permalink
docs: Schema::create_enum_from_active_enum (SeaQL/sea-orm#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Dec 22, 2021
1 parent 57bf2cf commit 764d615
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion SeaORM/docs/04-generate-database-schema/02-create-enum.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ pub mod active_enum {

### PostgreSQL

Enum in PostgreSQL is defined as a custom type, it can be created with [`Schema::create_enum_from_entity`](https://docs.rs/sea-orm/0.*/sea_orm/schema/struct.Schema.html#method.create_enum_from_entity) method.
Enum in PostgreSQL is defined as a custom type, it can be created from an `Entity` with [`Schema::create_enum_from_entity`](https://docs.rs/sea-orm/0.*/sea_orm/schema/struct.Schema.html#method.create_enum_from_entity) method.

Or, it can be created directly from `ActiveEnum` with [`Schema::create_enum_from_active_enum`](https://docs.rs/sea-orm/0.*/sea_orm/schema/struct.Schema.html#method.create_enum_from_active_enum) method.

```rust
use sea_orm::{Schema, Statement};
Expand All @@ -129,6 +131,14 @@ assert_eq!(
),]
);

assert_eq!(
db_postgres.build(&schema.create_enum_from_active_enum::<Tea>()),
Statement::from_string(
db_postgres,
r#"CREATE TYPE "tea" AS ENUM ('EverydayTea', 'BreakfastTea')"#.to_owned()
)
);

assert_eq!(
db_postgres.build(&schema.create_table_from_entity(active_enum::Entity)),
Statement::from_string(
Expand Down

0 comments on commit 764d615

Please sign in to comment.