|
@@ -9,6 +9,7 @@
|
|
#include <drogon/utils/Utilities.h>
|
|
#include <drogon/utils/Utilities.h>
|
|
#include <string>
|
|
#include <string>
|
|
|
|
|
|
|
|
+using namespace drogon;
|
|
using namespace drogon_model::hello_world;
|
|
using namespace drogon_model::hello_world;
|
|
|
|
|
|
const std::string Fortune::Cols::id = "id";
|
|
const std::string Fortune::Cols::id = "id";
|
|
@@ -17,10 +18,9 @@ const std::string Fortune::primaryKeyName = "id";
|
|
const bool Fortune::hasPrimaryKey = true;
|
|
const bool Fortune::hasPrimaryKey = true;
|
|
const std::string Fortune::tableName = "fortune";
|
|
const std::string Fortune::tableName = "fortune";
|
|
|
|
|
|
-const std::vector<typename Fortune::MetaData> Fortune::_metaData={
|
|
|
|
-{"id","int32_t","integer",4,0,1,1},
|
|
|
|
-{"message","std::string","character varying",2048,0,0,1}
|
|
|
|
-};
|
|
|
|
|
|
+const std::vector<typename Fortune::MetaData> Fortune::_metaData = {
|
|
|
|
+ {"id", "int32_t", "integer", 4, 0, 1, 1},
|
|
|
|
+ {"message", "std::string", "character varying", 2048, 0, 0, 1}};
|
|
const std::string &Fortune::getColumnName(size_t index) noexcept(false)
|
|
const std::string &Fortune::getColumnName(size_t index) noexcept(false)
|
|
{
|
|
{
|
|
assert(index < _metaData.size());
|
|
assert(index < _metaData.size());
|
|
@@ -28,22 +28,24 @@ const std::string &Fortune::getColumnName(size_t index) noexcept(false)
|
|
}
|
|
}
|
|
Fortune::Fortune(const Row &r) noexcept
|
|
Fortune::Fortune(const Row &r) noexcept
|
|
{
|
|
{
|
|
- if(!r["id"].isNull())
|
|
|
|
- {
|
|
|
|
- _id=std::make_shared<int32_t>(r["id"].as<int32_t>());
|
|
|
|
- }
|
|
|
|
- if(!r["message"].isNull())
|
|
|
|
- {
|
|
|
|
- _message=std::make_shared<std::string>(r["message"].as<std::string>());
|
|
|
|
- }
|
|
|
|
|
|
+ if (!r["id"].isNull())
|
|
|
|
+ {
|
|
|
|
+ _id = std::make_shared<int32_t>(r["id"].as<int32_t>());
|
|
|
|
+ }
|
|
|
|
+ if (!r["message"].isNull())
|
|
|
|
+ {
|
|
|
|
+ _message =
|
|
|
|
+ std::make_shared<std::string>(r["message"].as<std::string>());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-const int32_t & Fortune::getValueOfId(const int32_t &defaultValue) const noexcept
|
|
|
|
|
|
+const int32_t &Fortune::getValueOfId() const noexcept
|
|
{
|
|
{
|
|
- if(_id)
|
|
|
|
|
|
+ const static int32_t defaultValue = int32_t();
|
|
|
|
+ if (_id)
|
|
return *_id;
|
|
return *_id;
|
|
return defaultValue;
|
|
return defaultValue;
|
|
}
|
|
}
|
|
-std::shared_ptr<const int32_t> Fortune::getId() const noexcept
|
|
|
|
|
|
+const std::shared_ptr<int32_t> &Fortune::getId() const noexcept
|
|
{
|
|
{
|
|
return _id;
|
|
return _id;
|
|
}
|
|
}
|
|
@@ -53,19 +55,20 @@ void Fortune::setId(const int32_t &id) noexcept
|
|
_dirtyFlag[0] = true;
|
|
_dirtyFlag[0] = true;
|
|
}
|
|
}
|
|
|
|
|
|
-const typename Fortune::PrimaryKeyType & Fortune::getPrimaryKey() const
|
|
|
|
|
|
+const typename Fortune::PrimaryKeyType &Fortune::getPrimaryKey() const
|
|
{
|
|
{
|
|
assert(_id);
|
|
assert(_id);
|
|
return *_id;
|
|
return *_id;
|
|
}
|
|
}
|
|
|
|
|
|
-const std::string & Fortune::getValueOfMessage(const std::string &defaultValue) const noexcept
|
|
|
|
|
|
+const std::string &Fortune::getValueOfMessage() const noexcept
|
|
{
|
|
{
|
|
- if(_message)
|
|
|
|
|
|
+ const static std::string defaultValue = std::string();
|
|
|
|
+ if (_message)
|
|
return *_message;
|
|
return *_message;
|
|
return defaultValue;
|
|
return defaultValue;
|
|
}
|
|
}
|
|
-std::shared_ptr<const std::string> Fortune::getMessage() const noexcept
|
|
|
|
|
|
+const std::shared_ptr<std::string> &Fortune::getMessage() const noexcept
|
|
{
|
|
{
|
|
return _message;
|
|
return _message;
|
|
}
|
|
}
|
|
@@ -80,23 +83,19 @@ void Fortune::setMessage(std::string &&message) noexcept
|
|
_dirtyFlag[1] = true;
|
|
_dirtyFlag[1] = true;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
void Fortune::updateId(const uint64_t id)
|
|
void Fortune::updateId(const uint64_t id)
|
|
{
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
const std::vector<std::string> &Fortune::insertColumns() noexcept
|
|
const std::vector<std::string> &Fortune::insertColumns() noexcept
|
|
{
|
|
{
|
|
- static const std::vector<std::string> _inCols={
|
|
|
|
- "id",
|
|
|
|
- "message"
|
|
|
|
- };
|
|
|
|
|
|
+ static const std::vector<std::string> _inCols = {"id", "message"};
|
|
return _inCols;
|
|
return _inCols;
|
|
}
|
|
}
|
|
|
|
|
|
void Fortune::outputArgs(drogon::orm::internal::SqlBinder &binder) const
|
|
void Fortune::outputArgs(drogon::orm::internal::SqlBinder &binder) const
|
|
{
|
|
{
|
|
- if(getId())
|
|
|
|
|
|
+ if (getId())
|
|
{
|
|
{
|
|
binder << getValueOfId();
|
|
binder << getValueOfId();
|
|
}
|
|
}
|
|
@@ -104,7 +103,7 @@ void Fortune::outputArgs(drogon::orm::internal::SqlBinder &binder) const
|
|
{
|
|
{
|
|
binder << nullptr;
|
|
binder << nullptr;
|
|
}
|
|
}
|
|
- if(getMessage())
|
|
|
|
|
|
+ if (getMessage())
|
|
{
|
|
{
|
|
binder << getValueOfMessage();
|
|
binder << getValueOfMessage();
|
|
}
|
|
}
|
|
@@ -117,9 +116,9 @@ void Fortune::outputArgs(drogon::orm::internal::SqlBinder &binder) const
|
|
const std::vector<std::string> Fortune::updateColumns() const
|
|
const std::vector<std::string> Fortune::updateColumns() const
|
|
{
|
|
{
|
|
std::vector<std::string> ret;
|
|
std::vector<std::string> ret;
|
|
- for(size_t i=0;i<sizeof(_dirtyFlag);i++)
|
|
|
|
|
|
+ for (size_t i = 0; i < sizeof(_dirtyFlag); i++)
|
|
{
|
|
{
|
|
- if(_dirtyFlag[i])
|
|
|
|
|
|
+ if (_dirtyFlag[i])
|
|
{
|
|
{
|
|
ret.push_back(getColumnName(i));
|
|
ret.push_back(getColumnName(i));
|
|
}
|
|
}
|
|
@@ -129,9 +128,9 @@ const std::vector<std::string> Fortune::updateColumns() const
|
|
|
|
|
|
void Fortune::updateArgs(drogon::orm::internal::SqlBinder &binder) const
|
|
void Fortune::updateArgs(drogon::orm::internal::SqlBinder &binder) const
|
|
{
|
|
{
|
|
- if(_dirtyFlag[0])
|
|
|
|
|
|
+ if (_dirtyFlag[0])
|
|
{
|
|
{
|
|
- if(getId())
|
|
|
|
|
|
+ if (getId())
|
|
{
|
|
{
|
|
binder << getValueOfId();
|
|
binder << getValueOfId();
|
|
}
|
|
}
|
|
@@ -140,9 +139,9 @@ void Fortune::updateArgs(drogon::orm::internal::SqlBinder &binder) const
|
|
binder << nullptr;
|
|
binder << nullptr;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(_dirtyFlag[1])
|
|
|
|
|
|
+ if (_dirtyFlag[1])
|
|
{
|
|
{
|
|
- if(getMessage())
|
|
|
|
|
|
+ if (getMessage())
|
|
{
|
|
{
|
|
binder << getValueOfMessage();
|
|
binder << getValueOfMessage();
|
|
}
|
|
}
|
|
@@ -155,21 +154,21 @@ void Fortune::updateArgs(drogon::orm::internal::SqlBinder &binder) const
|
|
Json::Value Fortune::toJson() const
|
|
Json::Value Fortune::toJson() const
|
|
{
|
|
{
|
|
Json::Value ret;
|
|
Json::Value ret;
|
|
- if(getId())
|
|
|
|
|
|
+ if (getId())
|
|
{
|
|
{
|
|
- ret["id"]=getValueOfId();
|
|
|
|
|
|
+ ret["id"] = getValueOfId();
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- ret["id"]=Json::Value();
|
|
|
|
|
|
+ ret["id"] = Json::Value();
|
|
}
|
|
}
|
|
- if(getMessage())
|
|
|
|
|
|
+ if (getMessage())
|
|
{
|
|
{
|
|
- ret["message"]=getValueOfMessage();
|
|
|
|
|
|
+ ret["message"] = getValueOfMessage();
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- ret["message"]=Json::Value();
|
|
|
|
|
|
+ ret["message"] = Json::Value();
|
|
}
|
|
}
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|