Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,39 @@ struct Submodel {
}
```

### Flatten support

Atmosphere supports flattening nested structs into the parent table using `#[sql(flatten)]`.
This generates columns for the nested type at compile time and binds them on INSERT/UPDATE.

```rust
use atmosphere::prelude::*;

#[derive(FlattenFields)]
struct ContactInfo {
email: String,
phone: Option<String>,
}

#[table(schema = "public", name = "user")]
struct User {
#[sql(pk)]
id: i32,
name: String,
#[sql(flatten, prefix)]
contact: ContactInfo,
}
```

Prefix modes:
- `#[sql(flatten)]` no prefix (columns must be unique)
- `#[sql(flatten, prefix)]` or `#[sql(flatten, prefix = auto)]` auto prefix with field name
- `#[sql(flatten, prefix = "c_")]` custom prefix

Notes:
- Changing prefix requires a database migration (column names change).
- Recommended max nesting depth: 2 levels (Postgres identifier limit is 63 chars).

## Contribution

We welcome contributions! Please see [our contribution guidelines](CONTRIBUTING.md) for more details.
Expand Down
Loading