Skip to content

Commit

Permalink
Edit
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Jun 1, 2024
1 parent 3295c76 commit 33caf1c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
23 changes: 15 additions & 8 deletions SeaORM/docs/04-generate-entity/02-entity-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ Optionally, you can also specify the database schema or database name by `schema

By default, all column names are assumed to be in snake_case. You can override this behaviour for all columns in a model by specifying the `rename_all` attribute.

```rust
#[sea_orm(rename_all = "camelCase")]
pub struct Model { ... }
```

<details>
<summary>You can find a list of valid values for the `rename_all` attribute below</summary>

Expand All @@ -62,20 +67,22 @@ By default, all column names are assumed to be in snake_case. You can override t

</details>

```rust
#[sea_orm(rename_all = "camelCase")]
pub struct Model { ... }
```

## Column

### Column Name

All column names are assumed to be in snake-case, unless overridden by the [`rename_all`](#column-names) attribute on Model. You can override the column name by specifying the `column_name` attribute.
You can override the column name by specifying the `column_name` attribute.

```rust
#[sea_orm(column_name = "name")]
pub name: String
#[derive(DeriveEntityModel)]
#[sea_orm(table_name = "user", rename_all = "camelCase")]
pub struct Model {
#[sea_orm(primary_key)]
id: i32,
first_name: String, // firstName
#[sea_orm(column_name = "lAsTnAmE")]
last_name: String, // lAsTnAmE
}
```

### Column Type
Expand Down
18 changes: 8 additions & 10 deletions SeaORM/docs/04-generate-entity/04-enumeration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ For string enums, in addition to being able to specify the string value for each

```rust
#[derive(EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "String(Some(1))")]
#[sea_orm(rs_type = "String", db_type = "String(StringLen::N(1))")]
pub enum Category {
#[sea_orm(string_value = "B")]
Big,
Expand All @@ -23,22 +23,20 @@ pub enum Category {

```rust
#[derive(EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "String(Some(1))")]
#[sea_orm(rs_type = "String", db_type = "String(StringLen::None)")]
pub enum Category {
#[sea_orm(string_value = "bigTask")]
BigTask,
#[sea_orm(string_value = "smallBreak")]
SmallWork,
}
```
Alternatively, you could write:

The above is equivalent to:

```rust
#[derive(EnumIter, DeriveActiveEnum)]
#[sea_orm(
rs_type = "String",
db_type = "String(Some(1))",
rename_all = "camelCase"
)]
#[sea_orm(rs_type = "String", db_type = "String(StringLen::None)", rename_all = "camelCase")]
pub enum Category {
BigTask,
SmallWork,
Expand Down Expand Up @@ -159,7 +157,7 @@ use sea_orm::entity::prelude::*;
#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(
rs_type = "String",
db_type = "String(Some(1))",
db_type = "String(StringLen::N(1))",
enum_name = "category"
)]
pub enum Category {
Expand Down Expand Up @@ -230,7 +228,7 @@ use sea_orm::entity::prelude::*;

// Define the `Category` active enum
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "String(Some(1))")]
#[sea_orm(rs_type = "String", db_type = "String(StringLen::N(1))")]
pub enum Category {
#[sea_orm(string_value = "B")]
Big,
Expand Down
4 changes: 2 additions & 2 deletions SeaORM/docs/09-schema-statement/02-create-enum.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Model {
}

#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "String(Some(1))")]
#[sea_orm(rs_type = "String", db_type = "String(StringLen::N(1))")]
pub enum Category {
#[sea_orm(string_value = "B")]
Big,
Expand Down Expand Up @@ -69,7 +69,7 @@ assert_eq!(

```rust
#[derive(Clone, Debug, PartialEq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "String(None)")]
#[sea_orm(rs_type = "String", db_type = "String(StringLen::None)")]
pub enum StringValue {
#[sea_orm(string_value = "")]
Member1,
Expand Down

0 comments on commit 33caf1c

Please sign in to comment.