You may generate SQL queries or YQL queries (for YDB) from external .sql/.yql files. To do this, call the following cmake function in your CMakeLists.txt:
It will generate the samples_postgres_service/sql_queries.hpp
file with following variable:
And the definition for each statement in samples_postgres_service/sql_queries.cpp
looks something like that:
You may use it as usual by passing to storages::postgres::Cluster::Execute()
for SQL files or ydb::TableClient::ExecuteDataQuery()
for YQL files:
While writing tests, you can check the coverage of your SQL/YQL queries using the sql_coverage
plugin.
To use it, you need to pass the target with generated queries to the userver_testsuite_add_simple
(or userver_testsuite_add
) function in your CMakeLists.txt:
It will enable the sql_coverage
plugin and add coverage test that will run with the other tests.