Rust Advanced Data Operations
This page combines the Rust APIs into application-sized patterns using the generated School Management fixture.
Search page with rows and two facets
let rows = Q::schools()
.with_name_containing("Primary")
.select_school_type_with(Q::school_types_minimal().select_code().select_name())
.select_platform_with(Q::platforms_minimal().select_name())
.facet_by_school_type_as_with_options(
"schoolTypes",
Q::school_types_minimal()
.with_code_in(["PRIMARY", "SECONDARY"])
.select_code().select_name().count_schools_as("schoolCount"),
true,
)
.facet_by_platform_as_with_options(
"platforms",
Q::platforms_minimal().select_name().count_schools_as("schoolCount"),
false,
)
.order_by_id_desc()
.top(50)
.comment("Search schools with dashboard facets")
.purpose("Render the authorized operations dashboard")
.execute_for_list(&context)
.await?;
let type_buckets = rows.facet("schoolTypes");
let platform_buckets = rows.facet("platforms");
The child predicate limits the allowed bucket domain. The Boolean independently controls include-all versus matched-only behavior.
Deep graph and per-parent Top-N
let platforms = Q::platforms()
.select_name()
.select_school_list_with(
Q::schools()
.select_name()
.select_school_type_with(
Q::school_types_minimal().select_code().select_name())
.order_by_student_capacity_desc()
.top(3),
)
.comment("Load each platform and its three largest schools")
.purpose("Render the authorized platform capacity review")
.execute_for_list(&context)
.await?;
The child top(3) is a per-parent limit. Verify the chosen provider plan rather
than reproducing it with an in-memory slice.
Grouped and relation analytics
let distribution = Q::schools()
.group_by_school_type()
.count_as("schoolCount")
.sum_student_capacity_as("capacityTotal")
.avg_student_capacity_as("capacityAverage")
.comment("Aggregate school capacity by type")
.purpose("Build the authorized capacity report")
.execute_for_rows(&context)
.await?;
let cards = Q::school_types_minimal()
.select_code().select_name()
.count_schools_as("schoolCount")
.sum_student_capacity_of_schools_as("capacityTotal", Q::schools())
.comment("Calculate type-level school metrics")
.purpose("Render the authorized type cards")
.execute_for_list(&context)
.await?;
distribution contains compact analytic rows; cards contains typed parents
with named relation metrics.
Audited read-modify-save
let mut school = Q::schools()
.with_id_is(school_id)
.select_platform_with(Q::platforms_minimal().select_name())
.select_school_type_with(Q::school_types_minimal().select_code())
.comment("Load the complete school for capacity approval")
.purpose("Apply an authorized capacity revision")
.execute_for_one(&context)
.await?
.expect("school must exist");
school.update_student_capacity(new_capacity);
let school = school
.audit_as("Approve revised student capacity")
.save(&context)
.await?;
Retain the returned entity to preserve the authoritative version. Continue with Transactions, Best Practices, and DataOps Analytics for existing Rust deep dives.