#include "view.hpp"
#include <fmt/format.h>
namespace sample {
const {
request.
GetHttpResponse().
SetContentType(http::content_type::kApplicationJson);
3,
std::chrono::milliseconds(1100),
ydb::TransactionMode::kStaleRO
};
static const ydb::Query kSelectQuery = {
"--!syntax_v1\n"
"DECLARE $service_key AS String;"
"DECLARE $channel_keys AS List<Int64>;"
"DECLARE $created_key AS Timestamp;"
"SELECT id, name, service, channel, created, state "
"FROM events VIEW sample_index "
"WHERE service = $service_key AND channel IN $channel_keys "
"AND created > $created_key;",
};
auto response = Ydb().ExecuteDataQuery(
query_params,
kSelectQuery,
"$service_key",
request_json["service"].As<std::string>(),
"$channel_keys",
request_json["channels"].As<std::vector<int64_t>>(),
"$created_key",
request_json["created"].As<std::chrono::system_clock::time_point>()
);
if (response.GetCursorCount() != 1) {
throw std::runtime_error("Unexpected response data");
}
for (auto row : response.GetSingleCursor()) {
item["id"] = row.Get<std::string>("id");
item["name"] = row.Get<ydb::Utf8>("name").GetUnderlying();
item["service"] = row.Get<std::string>("service");
item["channel"] = row.Get<std::int64_t>("channel");
item["created"] = row.Get<std::chrono::system_clock::time_point>("created");
auto state = row.Get<std::optional<formats::json::Value>>("state");
if (state) {
item["state"] = std::move(*state);
}
}
}
}