Add Visione backend foundation
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#include "repositories/Sql.h"
|
||||
|
||||
#include <drogon/orm/Field.h>
|
||||
#include <drogon/orm/ResultIterator.h>
|
||||
#include <drogon/orm/RowIterator.h>
|
||||
|
||||
namespace visione::repositories
|
||||
{
|
||||
Json::Value rowToJson(const drogon::orm::Row &row)
|
||||
{
|
||||
Json::Value object(Json::objectValue);
|
||||
for (const auto &field : row)
|
||||
{
|
||||
if (field.isNull())
|
||||
{
|
||||
object[field.name()] = Json::nullValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
object[field.name()] = field.as<std::string>();
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
Json::Value resultToJson(const drogon::orm::Result &result)
|
||||
{
|
||||
Json::Value array(Json::arrayValue);
|
||||
for (const auto &row : result)
|
||||
{
|
||||
array.append(rowToJson(row));
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
std::string nullableString(const Json::Value &value, const std::string &key)
|
||||
{
|
||||
if (!value.isMember(key) || value[key].isNull())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
return value[key].asString();
|
||||
}
|
||||
} // namespace visione::repositories
|
||||
Reference in New Issue
Block a user