C++ Data Operations
Read a bounded list
Use the Quick Start workspace. Its editable
cpp_app_console/src/business.hpp contains the following bounded read.
These names belong to the cpp_graph_save model; use your own generated
Assist for another model.
inline const ::teaql::SmartList<Model>& loadEntities(::teaql::UserContext& user_context) {
auto Q = user_context.queries<::cpp_graph_save::query_factory>();
return ::cpp_graph_save::require_value(
Q.tenants()
.selectSelfFields()
.orderByIdAsc()
.limit(20)
.comment("Load a bounded initial business view")
.purpose("Demonstrate explicit generated query intent")
.executeForList(user_context)
.wait());
}
The helper's Model alias is ::cpp_graph_save::Tenant. It selects complete
scalar state, uses stable ID ordering, limits the list and supplies both what
is being read and why. Comment and purpose may appear in either order.
Execution receives the same user_context that owns Q.
Keep results within their Context
The result is a borrowed const SmartList<Model>&, not an independently owned
container. require_value checks the runtime result; .wait() completes the
operation. Consume entities and E results before closing their Context.
An ordinary wrapper or reference does not extend that lifetime.
Read values without implicit I/O
The starter's readIdentity helper uses E::tenant(entity).getId().unwrap().
Read selected fields with the corresponding generated E workflow. NotLoaded,
NULL, loaded values and loaded empty collections retain distinct meanings.
Getters do not execute a missing query. Select relationships explicitly;
selectSelfFields() alone does not load every relationship.
Update authoritative state
The same file provides updateEntity(user_context, id, reason, change). Its
application callback changes an entity after the helper:
- Queries the tenant by ID with complete scalar state, comment and purpose.
- Rejects a missing row and copies the loaded entity into a managed mutable
object using
user_context.make<Model>(*existing). - Invokes the application change callback.
- Wraps the entity with
std::move(entity).audit_as(reason)and executesAuditedSaveExt<Model>::save(..., user_context).wait().
Read assist/tenant/write.md and assist/tenant/fields/name.md for the current
mutation methods before writing that callback. Supply a non-empty business
reason. The returned saved entity also borrows its Context. Keep optimistic
version checks and reload authoritative state when resolving a conflict.
The starter smoke exercises a no-op Save. It does not verify an arbitrary change callback. Add a test that changes a field, saves and reads it back; use the retained graph suite for the separate multi-entity examples and their evidence.
Continue to graphs, pages and streams
Business Scenarios maps each task to its generated guide. Relationship selection, grouped summaries and facets have model-specific signatures. Scalar streaming does not perform relation or aggregate enhancement, and streams must finish or close before Context reclamation.
For an outer transaction, use its transaction-owned save and query operations from Write/runtime Assist. Running ordinary Q through the surrounding UserContext does not implicitly join that transaction. Treat an audit failure after commit as committed persistence with failed delivery.