Logo
Explore Help
Sign In
phundrak/georm
1
0
Fork 0
You've already forked georm
Code Issues Pull Requests Actions Packages Releases Wiki Activity
georm/src/defaultable.rs

11 lines
298 B
Rust
Raw Normal View History

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-04 22:15:38 +02:00
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;
}
Copy Permalink
Powered by Gitea Version: 1.23.7 Page: 281ms Template: 23ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API