Skip to main content

TeaQL Now Supports C++20

· 3 min read
TeaQL Team
Core Team

How long can you keep the result of a C++ query? In TeaQL, the query below borrows its result from the UserContext that executes it. When that context closes, the borrow ends. The example makes the lifetime visible in the application code.

TeaQL now supports C++20. From one model you can generate a native domain library, a runnable SQLite console, and Assist guides for the generated API.

Run the SQLite console​

The example models a tenant, its documents, and their entries. During setup the starter creates a tenant through an audited graph save, then reads it back through a bounded query. The console prints the tenant ID and the number of tenants it loaded. It uses an in-memory SQLite database.

Use Linux x86_64 with Conan 2.35 and activate the TeaQL C++ 0.2.0 native toolchain in Bash. Run the commands in an empty directory. The example keeps its Conan cache inside that directory. Toolchain setup

curl -fsSLo main.xml https://raw.githubusercontent.com/teaql/teaql-cpp/d0730d124d4f3a0970e137df7eea25c63730c033/examples/graph_save_console/models/main.xml
curl -fsSLo console.zip -H 'Content-Type: application/xml' \
--data-binary @main.xml https://api.teaql.io/latest/cpp-app-console
unzip -q console.zip -d console

export CONAN_HOME="$PWD/.conan-teaql"
cd console
conan remote add teaql https://nexus.teaql.io/repository/conan-hosted/conan
conan install . -r teaql --build=never \
-pr:h profiles/linux-x86_64-clang23-debug \
-pr:b profiles/linux-x86_64-clang23-debug -of build/conan
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=conan/conan_toolchain.cmake \
-DCMAKE_BUILD_TYPE=Debug -DTEAQL_RUNTIME_MODE=release
cmake --build build --parallel 3
ctest --test-dir build --output-on-failure --no-tests=error
./build/cpp_app_console/teaql_console

The smoke test passes and the program prints these two lines after the audit log:

1
Loaded 1 entities

This run used the public generator and fetched teaql-cpp/0.2.0 and sqlite3/3.53.2 from the TeaQL Conan registry into an empty cache. The published binary profile uses Clang 23, libstdc++11, and Debug. TeaQL C++ release

Read the query and its lifetime together​

The generated workspace puts the editable application in cpp_app_console/. Its bounded query lives in src/business.hpp.

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 model supplies the typed tenants() entry point and its selectors. The application supplies the limit, what it is reading, and why. The return type is a reference. Consume it while user_context is open. If the data needs to outlive that scope, copy it into the destination scope explicitly.

The public Preview page lets you inspect the C++ workspace guide and Assist for Query, Write, and Stream. Write shows how an audit reason travels with a save and how multiple saves can share one transaction. C++ Assist previews

C++ joins Java, Rust, Go, Swift, Python, .NET, and TypeScript. Across all eight runtimes, a TeaQL model generates typed query APIs with the same familiar shape. Record what you are reading and why, execute through a UserContext, and attach an audit reason when you save.