#[derive(FromAnyRow)]Expand description
Re-export of the procedural macro for deriving FromRow for AnyRow and AnyImpl.
This macro facilitates scanning arbitrary query results (via AnyRow) into
Rust structs, handling necessary type conversions (especially for temporal types).
Derives the FromRow trait for AnyRow and the AnyImpl trait.
This procedural macro generates an implementation of sqlx::FromRow<'r, sqlx::any::AnyRow>
for the target struct, allowing it to be scanned directly from database results when
using sqlx::Any driver (which Bottle ORM uses internally).
It also implements the AnyImpl trait, which provides necessary column metadata used
by the QueryBuilder for dynamic query construction.
§Features
- Automatic Field Mapping: Maps database columns to struct fields by name.
- DateTime Handling: Includes special logic to handle
DateTimetypes, often required when dealing with theAnydriver’s type erasure or JSON serialization fallback. - Metadata Generation: Automatically generates
AnyInfofor each field.
§Requirements
The struct must have named fields. Tuple structs and unit structs are not supported.
§Example
ⓘ
use bottle_orm::{FromAnyRow, AnyImpl};
use chrono::{DateTime, Utc};
#[derive(FromAnyRow)]
struct UserCount {
count: i64,
last_active: DateTime<Utc>,
}
// Usage with QueryBuilder:
// let stats: UserCount = db.model::<User>().select("count(*), last_active").first().await?;