georm/src/defaultable.rs
Lucien Cartier-Tilet 9cb87105bb
feat: add defaultable field support with companion struct generation
Introduces support for `#[georm(defaultable)]` attribute on entity
fields. When fields are marked as defaultable, generates companion
`<Entity>Default` structs where defaultable fields become `Option<T>`,
enabling easier entity creation when some fields have database defaults
or are auto-generated.

Key features:
- Generates `<Entity>Default` structs with optional defaultable fields
- Implements `Defaultable<Id, Entity>` trait with async `create` method
- Validates that `Option<T>` fields cannot be marked as defaultable
- Preserves field visibility in generated companion structs
- Only generates companion struct when defaultable fields are present
2025-06-06 11:09:18 +02:00

11 lines
298 B
Rust

pub trait Defaultable<Id, Entity> {
/// Creates an entity in the database.
///
/// # Errors
/// Returns any error the database may have encountered
fn create(
&self,
pool: &sqlx::PgPool,
) -> impl std::future::Future<Output = sqlx::Result<Entity>> + Send;
}