Skip to main content

TypeScript Business Scenarios

TeaQL TypeScript has a Node SQL profile and a browser-safe federal client profile. Keep those entry points separate; importing the root/browser client must not pull pg, mysql2, or better-sqlite3 into a browser bundle.

Query a Node SQL provider

const result = await Q.customerOrders()
.comment("Find matching orders")
.withOrderNumberContaining("WEB-")
.orderByIdAscending()
.offset(0)
.limit(20)
.purpose("Prepare the authorized order review page")
.executeForList(ctx);

purpose() returns ExecutableCustomerOrderRequest. The ordinary builder cannot execute. Context provides the data service and trusted runtime state.

Relations and per-parent Top-N

Generated reverse relations expose select...With(childRequest). Configure order and limit on the child Request, attach it to the parent before purpose, and inspect the SQL trace for ROW_NUMBER() OVER (PARTITION BY ...). Do not report an application slice or overfetch as an exact database plan.

Aggregates and facets

Generated Requests provide count, numeric aggregate methods, groupBy..., and facetBy...As for object references. PostgreSQL, MySQL and SQLite executions used native COUNT/SUM/GROUP BY. Apply the same active filter to page rows, count, totals and facet Requests.

Create and audited save

const order = Q.customerOrders()
.comment("Create a validated order")
.purpose("Persist an authorized checkout")
.newEntity(ctx);

order.updateOrderNumber("WEB-10001");
await order.auditAs("Create validated checkout order").save(ctx);

The runtime rejects missing audit intent and stale versions and emits both mutation-audit paths.

Federate to Rust

The generated domain client can serialize its SelectQuery through the TeaQL Federal Protocol /query endpoint. The server—not client JSON—owns tenant, authenticated user, permissions, request policy, approved purpose policy and provider selection.

Treat unknown fields/operators, deep paths, excessive IN lists/page sizes and forbidden sorts as protocol errors. Do not silently ignore them or degrade to an unfiltered query. Compare a federated response with a direct backend query when qualifying a new protocol/provider combination.

Failure checklist

Check the generated Request source, current runtime package resolution, explicit Node SQL subpath, UserContext resources and native trace. A copied node_modules runtime is not reproducible evidence; pin the generated project to the intended package version or current workspace artifact.