Skip to content

Commit

Permalink
Add Documentation For New Attributes SeaQL/sea-orm#2160
Browse files Browse the repository at this point in the history
  • Loading branch information
anshap1719 committed Apr 28, 2024
1 parent ead1602 commit 2bb8a12
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
24 changes: 22 additions & 2 deletions SeaORM/docs/04-generate-entity/02-entity-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,36 @@ The `DeriveEntityModel` macro does all the heavy lifting of defining an `Entity`
The `table_name` attribute specifies the corresponding table in the database.
Optionally, you can also specify the database schema or database name by `schema_name`.

### Column Names

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.

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

- camelCase
- kebab-case
- mixed_case
- SCREAMING_SNAKE_CASE
- snake_case
- title_case
- UPPERCASE
- lowercase
- SCREAMING-KEBAB-CASE
- PascalCase

</details>

```rust
#[sea_orm(table_name = "cake", schema_name = "public")]
#[sea_orm(rename_all = "camelCase")]
pub struct Model { ... }
```

## Column

### Column Name

All column names are assumed to be in snake-case. You can override the column name by specifying the `column_name` attribute.
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.

```rust
#[sea_orm(column_name = "name")]
Expand Down
46 changes: 46 additions & 0 deletions SeaORM/docs/04-generate-entity/04-enumeration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ You can use Rust enums in model where the values are mapped to a database string

### String

For string enums, in addition to being able to specify the string value for each variant, you can also specify the `rename_all` attribute on the Enum if all the values should have string values based on case-transformations.

#### Manual string values

```rust
#[derive(EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "String(Some(1))")]
Expand All @@ -15,6 +19,48 @@ pub enum Category {
}
```

#### Derived string values from variants

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

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

- camelCase
- kebab-case
- mixed_case
- SCREAMING_SNAKE_CASE
- snake_case
- title_case
- UPPERCASE
- lowercase
- SCREAMING-KEBAB-CASE
- PascalCase

</details>

### Integers

```rust
Expand Down

0 comments on commit 2bb8a12

Please sign in to comment.