Skip to content

Commit 3295c76

Browse files
authored
Add Documentation For New Attributes SeaQL/sea-orm#2160 (#121)
1 parent 2e6032d commit 3295c76

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

SeaORM/docs/04-generate-entity/02-entity-structure.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,36 @@ The `DeriveEntityModel` macro does all the heavy lifting of defining an `Entity`
4242
The `table_name` attribute specifies the corresponding table in the database.
4343
Optionally, you can also specify the database schema or database name by `schema_name`.
4444

45+
### Column Names
46+
47+
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.
48+
49+
<details>
50+
<summary>You can find a list of valid values for the `rename_all` attribute below</summary>
51+
52+
- camelCase
53+
- kebab-case
54+
- mixed_case
55+
- SCREAMING_SNAKE_CASE
56+
- snake_case
57+
- title_case
58+
- UPPERCASE
59+
- lowercase
60+
- SCREAMING-KEBAB-CASE
61+
- PascalCase
62+
63+
</details>
64+
4565
```rust
46-
#[sea_orm(table_name = "cake", schema_name = "public")]
66+
#[sea_orm(rename_all = "camelCase")]
4767
pub struct Model { ... }
4868
```
4969

5070
## Column
5171

5272
### Column Name
5373

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

5676
```rust
5777
#[sea_orm(column_name = "name")]

SeaORM/docs/04-generate-entity/04-enumeration.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ You can use Rust enums in model where the values are mapped to a database string
44

55
### String
66

7+
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.
8+
9+
#### Manual string values
10+
711
```rust
812
#[derive(EnumIter, DeriveActiveEnum)]
913
#[sea_orm(rs_type = "String", db_type = "String(Some(1))")]
@@ -15,6 +19,48 @@ pub enum Category {
1519
}
1620
```
1721

22+
#### Derived string values from variants
23+
24+
```rust
25+
#[derive(EnumIter, DeriveActiveEnum)]
26+
#[sea_orm(rs_type = "String", db_type = "String(Some(1))")]
27+
pub enum Category {
28+
#[sea_orm(string_value = "bigTask")]
29+
BigTask,
30+
#[sea_orm(string_value = "smallBreak")]
31+
SmallWork,
32+
}
33+
```
34+
Alternatively, you could write:
35+
```rust
36+
#[derive(EnumIter, DeriveActiveEnum)]
37+
#[sea_orm(
38+
rs_type = "String",
39+
db_type = "String(Some(1))",
40+
rename_all = "camelCase"
41+
)]
42+
pub enum Category {
43+
BigTask,
44+
SmallWork,
45+
}
46+
```
47+
48+
<details>
49+
<summary>You can find a list of valid values for the `rename_all` attribute below</summary>
50+
51+
- camelCase
52+
- kebab-case
53+
- mixed_case
54+
- SCREAMING_SNAKE_CASE
55+
- snake_case
56+
- title_case
57+
- UPPERCASE
58+
- lowercase
59+
- SCREAMING-KEBAB-CASE
60+
- PascalCase
61+
62+
</details>
63+
1864
### Integers
1965

2066
```rust

0 commit comments

Comments
 (0)