Skip to content
Snippets Groups Projects
Commit 3ffd3f51 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

ENH: Better cli and documentation.

parent 13b955a1
No related branches found
No related tags found
No related merge requests found
Pipeline #12594 failed
......@@ -79,7 +79,9 @@ For the tests there is a slightly different setup required (with option `-D CMAK
3. `cmake -B . -D CMAKE_BUILD_TYPE=Debug ..`
* If your clang-format version is too old, formatting, linting etc. can be skipped:
`cmake -B . -D CMAKE_BUILD_TYPE=Debug -D SKIP_LINTING=ON ..`
4. `cmake --build .`
* Depending on the clang version it might be necessary to also add
`-DCMAKE_CXX_FLAGS="-Wno-unused-parameter"`
5. `cmake --build .`
### Run
......
......@@ -26,11 +26,14 @@
#include "caosdb/entity.h" // for Entity
#include "caosdb/exceptions.h" // for ConfigurationError
#include "caosdb/info.h" // for VersionInfo
#include "caosdb/logging.h" // for CAOSDB_LOG_TRACE
#include "caosdb/transaction.h" // for Transaction, ResultSet
#include <iostream> // for operator<<, basic_ostream, basic_ost...
#include <memory> // for unique_ptr, allocator, __shared_ptr_...
#include <string> // for operator<<, char_traits
auto logger_name = "libcaosdb";
auto main() -> int {
std::cout << "CaosDB C++ client (libcaosdb " << caosdb::LIBCAOSDB_VERSION_MINOR << "."
......@@ -51,19 +54,34 @@ auto main() -> int {
// retrieve an entity
auto transaction(connection->CreateTransaction());
transaction->RetrieveById("120");
transaction->Execute();
transaction->ExecuteAsynchronously();
auto t_stat = transaction->WaitForIt();
CAOSDB_LOG_INFO(logger_name) << "status: " << t_stat.GetCode()
<< " // " << t_stat.GetDescription();
const auto &result_set = transaction->GetResultSet();
// print information
const auto &ent = result_set.at(0);
const auto &props = ent.GetProperties();
std::cout << "Entity Name: " << ent.GetName() << std::endl;
std::cout << "Entity Description: " << ent.GetDescription() << std::endl;
std::cout << "Entity Properties: " << std::endl;
for (const auto &prop : props) {
std::cout << "----------\n" << prop.ToString() << std::endl;
if (result_set.size() > 0) {
// print information
const auto &ent = result_set.at(0);
const auto &props = ent.GetProperties();
std::cout << "Entity Name: " << ent.GetName() << std::endl;
std::cout << "Entity Description: " << ent.GetDescription() << std::endl;
std::cout << "Entity Properties: " << std::endl;
for (const auto &prop : props) {
std::cout << "----------\n" << prop.ToString() << std::endl;
}
} else {
std::cout << "No entity \"120\" retrieved, maybe it does not exist?\n" << std::endl;
}
// execute a query
std::string query("FIND Property \"Prop *\"");
std::cout << "Trying to execute a query:\n" << query << std::endl;
auto q_transaction(connection->CreateTransaction());
q_transaction->Query(query);
q_transaction->ExecuteAsynchronously();
t_stat = q_transaction->WaitForIt();
CAOSDB_LOG_INFO(logger_name) << "status: " << t_stat.GetCode()
<< " // " << t_stat.GetDescription();
return 0;
} catch (const caosdb::exceptions::ConfigurationError &exc) {
std::cout << "ConfigurationError: " << exc.what() << std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment