From 456d0034823d28e7389d84d5c4c81eb52b63434e Mon Sep 17 00:00:00 2001 From: An Tao Date: Fri, 13 Sep 2019 08:28:58 +0800 Subject: [PATCH] Add prefixes to column name variables in model classes (#242) --- drogon_ctl/templates/model_cc.csp | 16 ++--- drogon_ctl/templates/model_h.csp | 10 +-- orm_lib/src/sqlite3_impl/test/Groups.cc | 84 ++++++++++++------------- orm_lib/src/sqlite3_impl/test/Groups.h | 53 ++++++++-------- orm_lib/tests/Users.cc | 78 +++++++++++------------ orm_lib/tests/Users.h | 49 +++++++-------- 6 files changed, 144 insertions(+), 146 deletions(-) diff --git a/drogon_ctl/templates/model_cc.csp b/drogon_ctl/templates/model_cc.csp index 7e0172b2..3139a8a7 100644 --- a/drogon_ctl/templates/model_cc.csp +++ b/drogon_ctl/templates/model_cc.csp @@ -31,7 +31,7 @@ else <%c++for(auto col:cols){ %> -const std::string [[className]]::Cols::{%col._colName%} = "{%col._colName%}"; +const std::string [[className]]::Cols::_{%col._colName%} = "{%col._colName%}"; <%c++ }%> <%c++if(@@.get("hasPrimaryKey")<=1){%> @@ -167,33 +167,33 @@ const std::string &[[className]]::getColumnName(size_t index) noexcept(false) if(!col._isAutoVal) { - $$<<"void "<("<(p"<("<(p"<(std::move("<(std::move(p"<") { - $$<<"void "<>("<>(p"<>("columns"); for(size_t i=0;i }; @@ -89,7 +89,7 @@ auto cols=@@.get>("columns"); [[className]]() = default; <%c++ - for(auto col:cols) + for(const auto &col:cols) { $$<<" /** For column "<>("columns"); if(!col._isAutoVal) { $$<<" ///Set the value of the column "<") { - $$<<" void set"< &Groups::getGroupName() const noexcept { return _groupName; } -void Groups::setGroupName(const std::string &groupName) noexcept +void Groups::setGroupName(const std::string &pGroupName) noexcept { - _groupName = std::make_shared(groupName); + _groupName = std::make_shared(pGroupName); _dirtyFlag[1] = true; } -void Groups::setGroupName(std::string &&groupName) noexcept +void Groups::setGroupName(std::string &&pGroupName) noexcept { - _groupName = std::make_shared(std::move(groupName)); + _groupName = std::make_shared(std::move(pGroupName)); _dirtyFlag[1] = true; } @@ -146,9 +146,9 @@ const std::shared_ptr &Groups::getCreaterId() const noexcept { return _createrId; } -void Groups::setCreaterId(const uint64_t &createrId) noexcept +void Groups::setCreaterId(const uint64_t &pCreaterId) noexcept { - _createrId = std::make_shared(createrId); + _createrId = std::make_shared(pCreaterId); _dirtyFlag[2] = true; } @@ -163,14 +163,14 @@ const std::shared_ptr &Groups::getCreateTime() const noexcept { return _createTime; } -void Groups::setCreateTime(const std::string &createTime) noexcept +void Groups::setCreateTime(const std::string &pCreateTime) noexcept { - _createTime = std::make_shared(createTime); + _createTime = std::make_shared(pCreateTime); _dirtyFlag[3] = true; } -void Groups::setCreateTime(std::string &&createTime) noexcept +void Groups::setCreateTime(std::string &&pCreateTime) noexcept { - _createTime = std::make_shared(std::move(createTime)); + _createTime = std::make_shared(std::move(pCreateTime)); _dirtyFlag[3] = true; } @@ -185,9 +185,9 @@ const std::shared_ptr &Groups::getInviting() const noexcept { return _inviting; } -void Groups::setInviting(const uint64_t &inviting) noexcept +void Groups::setInviting(const uint64_t &pInviting) noexcept { - _inviting = std::make_shared(inviting); + _inviting = std::make_shared(pInviting); _dirtyFlag[4] = true; } @@ -202,9 +202,9 @@ const std::shared_ptr &Groups::getInvitingUserId() const noexcept { return _invitingUserId; } -void Groups::setInvitingUserId(const uint64_t &invitingUserId) noexcept +void Groups::setInvitingUserId(const uint64_t &pInvitingUserId) noexcept { - _invitingUserId = std::make_shared(invitingUserId); + _invitingUserId = std::make_shared(pInvitingUserId); _dirtyFlag[5] = true; } @@ -219,14 +219,14 @@ const std::shared_ptr &Groups::getAvatarId() const noexcept { return _avatarId; } -void Groups::setAvatarId(const std::string &avatarId) noexcept +void Groups::setAvatarId(const std::string &pAvatarId) noexcept { - _avatarId = std::make_shared(avatarId); + _avatarId = std::make_shared(pAvatarId); _dirtyFlag[6] = true; } -void Groups::setAvatarId(std::string &&avatarId) noexcept +void Groups::setAvatarId(std::string &&pAvatarId) noexcept { - _avatarId = std::make_shared(std::move(avatarId)); + _avatarId = std::make_shared(std::move(pAvatarId)); _dirtyFlag[6] = true; } @@ -241,9 +241,9 @@ const std::shared_ptr &Groups::getUuu() const noexcept { return _uuu; } -void Groups::setUuu(const double &uuu) noexcept +void Groups::setUuu(const double &pUuu) noexcept { - _uuu = std::make_shared(uuu); + _uuu = std::make_shared(pUuu); _dirtyFlag[7] = true; } @@ -258,14 +258,14 @@ const std::shared_ptr &Groups::getText() const noexcept { return _text; } -void Groups::setText(const std::string &text) noexcept +void Groups::setText(const std::string &pText) noexcept { - _text = std::make_shared(text); + _text = std::make_shared(pText); _dirtyFlag[8] = true; } -void Groups::setText(std::string &&text) noexcept +void Groups::setText(std::string &&pText) noexcept { - _text = std::make_shared(std::move(text)); + _text = std::make_shared(std::move(pText)); _dirtyFlag[8] = true; } @@ -287,17 +287,17 @@ const std::shared_ptr> &Groups::getAvatar() const noexcept { return _avatar; } -void Groups::setAvatar(const std::vector &avatar) noexcept +void Groups::setAvatar(const std::vector &pAvatar) noexcept { - _avatar = std::make_shared>(avatar); + _avatar = std::make_shared>(pAvatar); _dirtyFlag[9] = true; } -void Groups::setAvatar(const std::string &avatar) noexcept +void Groups::setAvatar(const std::string &pAvatar) noexcept { _avatar = - std::make_shared>(avatar.c_str(), - avatar.c_str() + avatar.length()); + std::make_shared>(pAvatar.c_str(), + pAvatar.c_str() + pAvatar.length()); _dirtyFlag[9] = true; } @@ -312,9 +312,9 @@ const std::shared_ptr &Groups::getIsDefault() const noexcept { return _isDefault; } -void Groups::setIsDefault(const bool &isDefault) noexcept +void Groups::setIsDefault(const bool &pIsDefault) noexcept { - _isDefault = std::make_shared(isDefault); + _isDefault = std::make_shared(pIsDefault); _dirtyFlag[10] = true; } diff --git a/orm_lib/src/sqlite3_impl/test/Groups.h b/orm_lib/src/sqlite3_impl/test/Groups.h index cde2a3c4..b25b74f6 100644 --- a/orm_lib/src/sqlite3_impl/test/Groups.h +++ b/orm_lib/src/sqlite3_impl/test/Groups.h @@ -31,17 +31,17 @@ class Groups public: struct Cols { - static const std::string group_id; - static const std::string group_name; - static const std::string creater_id; - static const std::string create_time; - static const std::string inviting; - static const std::string inviting_user_id; - static const std::string avatar_id; - static const std::string uuu; - static const std::string text; - static const std::string avatar; - static const std::string is_default; + static const std::string _group_id; + static const std::string _group_name; + static const std::string _creater_id; + static const std::string _create_time; + static const std::string _inviting; + static const std::string _inviting_user_id; + static const std::string _avatar_id; + static const std::string _uuu; + static const std::string _text; + static const std::string _avatar; + static const std::string _is_default; }; const static int primaryKeyNumber; @@ -69,8 +69,8 @@ class Groups /// empty shared_ptr object if the column is null const std::shared_ptr &getGroupName() const noexcept; /// Set the value of the column group_name - void setGroupName(const std::string &groupName) noexcept; - void setGroupName(std::string &&groupName) noexcept; + void setGroupName(const std::string &pGroupName) noexcept; + void setGroupName(std::string &&pGroupName) noexcept; /** For column creater_id */ /// Get the value of the column creater_id, returns the default value if the @@ -80,7 +80,7 @@ class Groups /// empty shared_ptr object if the column is null const std::shared_ptr &getCreaterId() const noexcept; /// Set the value of the column creater_id - void setCreaterId(const uint64_t &createrId) noexcept; + void setCreaterId(const uint64_t &pCreaterId) noexcept; /** For column create_time */ /// Get the value of the column create_time, returns the default value if @@ -90,8 +90,8 @@ class Groups /// empty shared_ptr object if the column is null const std::shared_ptr &getCreateTime() const noexcept; /// Set the value of the column create_time - void setCreateTime(const std::string &createTime) noexcept; - void setCreateTime(std::string &&createTime) noexcept; + void setCreateTime(const std::string &pCreateTime) noexcept; + void setCreateTime(std::string &&pCreateTime) noexcept; /** For column inviting */ /// Get the value of the column inviting, returns the default value if the @@ -101,7 +101,7 @@ class Groups /// empty shared_ptr object if the column is null const std::shared_ptr &getInviting() const noexcept; /// Set the value of the column inviting - void setInviting(const uint64_t &inviting) noexcept; + void setInviting(const uint64_t &pInviting) noexcept; /** For column inviting_user_id */ /// Get the value of the column inviting_user_id, returns the default value @@ -111,7 +111,7 @@ class Groups /// empty shared_ptr object if the column is null const std::shared_ptr &getInvitingUserId() const noexcept; /// Set the value of the column inviting_user_id - void setInvitingUserId(const uint64_t &invitingUserId) noexcept; + void setInvitingUserId(const uint64_t &pInvitingUserId) noexcept; /** For column avatar_id */ /// Get the value of the column avatar_id, returns the default value if the @@ -121,8 +121,8 @@ class Groups /// empty shared_ptr object if the column is null const std::shared_ptr &getAvatarId() const noexcept; /// Set the value of the column avatar_id - void setAvatarId(const std::string &avatarId) noexcept; - void setAvatarId(std::string &&avatarId) noexcept; + void setAvatarId(const std::string &pAvatarId) noexcept; + void setAvatarId(std::string &&pAvatarId) noexcept; /** For column uuu */ /// Get the value of the column uuu, returns the default value if the column @@ -132,7 +132,7 @@ class Groups /// empty shared_ptr object if the column is null const std::shared_ptr &getUuu() const noexcept; /// Set the value of the column uuu - void setUuu(const double &uuu) noexcept; + void setUuu(const double &pUuu) noexcept; /** For column text */ /// Get the value of the column text, returns the default value if the @@ -142,8 +142,8 @@ class Groups /// empty shared_ptr object if the column is null const std::shared_ptr &getText() const noexcept; /// Set the value of the column text - void setText(const std::string &text) noexcept; - void setText(std::string &&text) noexcept; + void setText(const std::string &pText) noexcept; + void setText(std::string &&pText) noexcept; /** For column avatar */ /// Get the value of the column avatar, returns the default value if the @@ -155,8 +155,8 @@ class Groups /// empty shared_ptr object if the column is null const std::shared_ptr> &getAvatar() const noexcept; /// Set the value of the column avatar - void setAvatar(const std::vector &avatar) noexcept; - void setAvatar(const std::string &avatar) noexcept; + void setAvatar(const std::vector &pAvatar) noexcept; + void setAvatar(const std::string &pAvatar) noexcept; /** For column is_default */ /// Get the value of the column is_default, returns the default value if the @@ -166,7 +166,7 @@ class Groups /// empty shared_ptr object if the column is null const std::shared_ptr &getIsDefault() const noexcept; /// Set the value of the column is_default - void setIsDefault(const bool &isDefault) noexcept; + void setIsDefault(const bool &pIsDefault) noexcept; static size_t getColumnNumber() noexcept { @@ -208,6 +208,5 @@ class Groups static const std::vector _metaData; bool _dirtyFlag[11] = {false}; }; - } // namespace sqlite3 } // namespace drogon_model diff --git a/orm_lib/tests/Users.cc b/orm_lib/tests/Users.cc index 2747ff9e..1ad8ccb7 100644 --- a/orm_lib/tests/Users.cc +++ b/orm_lib/tests/Users.cc @@ -12,15 +12,15 @@ using namespace drogon; using namespace drogon_model::postgres; -const std::string Users::Cols::user_id = "user_id"; -const std::string Users::Cols::user_name = "user_name"; -const std::string Users::Cols::password = "password"; -const std::string Users::Cols::org_name = "org_name"; -const std::string Users::Cols::signature = "signature"; -const std::string Users::Cols::avatar_id = "avatar_id"; -const std::string Users::Cols::id = "id"; -const std::string Users::Cols::salt = "salt"; -const std::string Users::Cols::admin = "admin"; +const std::string Users::Cols::_user_id = "user_id"; +const std::string Users::Cols::_user_name = "user_name"; +const std::string Users::Cols::_password = "password"; +const std::string Users::Cols::_org_name = "org_name"; +const std::string Users::Cols::_signature = "signature"; +const std::string Users::Cols::_avatar_id = "avatar_id"; +const std::string Users::Cols::_id = "id"; +const std::string Users::Cols::_salt = "salt"; +const std::string Users::Cols::_admin = "admin"; const std::string Users::primaryKeyName = "id"; const bool Users::hasPrimaryKey = true; const std::string Users::tableName = "users"; @@ -95,14 +95,14 @@ const std::shared_ptr &Users::getUserId() const noexcept { return _userId; } -void Users::setUserId(const std::string &userId) noexcept +void Users::setUserId(const std::string &pUserId) noexcept { - _userId = std::make_shared(userId); + _userId = std::make_shared(pUserId); _dirtyFlag[0] = true; } -void Users::setUserId(std::string &&userId) noexcept +void Users::setUserId(std::string &&pUserId) noexcept { - _userId = std::make_shared(std::move(userId)); + _userId = std::make_shared(std::move(pUserId)); _dirtyFlag[0] = true; } @@ -117,14 +117,14 @@ const std::shared_ptr &Users::getUserName() const noexcept { return _userName; } -void Users::setUserName(const std::string &userName) noexcept +void Users::setUserName(const std::string &pUserName) noexcept { - _userName = std::make_shared(userName); + _userName = std::make_shared(pUserName); _dirtyFlag[1] = true; } -void Users::setUserName(std::string &&userName) noexcept +void Users::setUserName(std::string &&pUserName) noexcept { - _userName = std::make_shared(std::move(userName)); + _userName = std::make_shared(std::move(pUserName)); _dirtyFlag[1] = true; } @@ -139,14 +139,14 @@ const std::shared_ptr &Users::getPassword() const noexcept { return _password; } -void Users::setPassword(const std::string &password) noexcept +void Users::setPassword(const std::string &pPassword) noexcept { - _password = std::make_shared(password); + _password = std::make_shared(pPassword); _dirtyFlag[2] = true; } -void Users::setPassword(std::string &&password) noexcept +void Users::setPassword(std::string &&pPassword) noexcept { - _password = std::make_shared(std::move(password)); + _password = std::make_shared(std::move(pPassword)); _dirtyFlag[2] = true; } @@ -161,14 +161,14 @@ const std::shared_ptr &Users::getOrgName() const noexcept { return _orgName; } -void Users::setOrgName(const std::string &orgName) noexcept +void Users::setOrgName(const std::string &pOrgName) noexcept { - _orgName = std::make_shared(orgName); + _orgName = std::make_shared(pOrgName); _dirtyFlag[3] = true; } -void Users::setOrgName(std::string &&orgName) noexcept +void Users::setOrgName(std::string &&pOrgName) noexcept { - _orgName = std::make_shared(std::move(orgName)); + _orgName = std::make_shared(std::move(pOrgName)); _dirtyFlag[3] = true; } @@ -183,14 +183,14 @@ const std::shared_ptr &Users::getSignature() const noexcept { return _signature; } -void Users::setSignature(const std::string &signature) noexcept +void Users::setSignature(const std::string &pSignature) noexcept { - _signature = std::make_shared(signature); + _signature = std::make_shared(pSignature); _dirtyFlag[4] = true; } -void Users::setSignature(std::string &&signature) noexcept +void Users::setSignature(std::string &&pSignature) noexcept { - _signature = std::make_shared(std::move(signature)); + _signature = std::make_shared(std::move(pSignature)); _dirtyFlag[4] = true; } @@ -205,14 +205,14 @@ const std::shared_ptr &Users::getAvatarId() const noexcept { return _avatarId; } -void Users::setAvatarId(const std::string &avatarId) noexcept +void Users::setAvatarId(const std::string &pAvatarId) noexcept { - _avatarId = std::make_shared(avatarId); + _avatarId = std::make_shared(pAvatarId); _dirtyFlag[5] = true; } -void Users::setAvatarId(std::string &&avatarId) noexcept +void Users::setAvatarId(std::string &&pAvatarId) noexcept { - _avatarId = std::make_shared(std::move(avatarId)); + _avatarId = std::make_shared(std::move(pAvatarId)); _dirtyFlag[5] = true; } @@ -244,14 +244,14 @@ const std::shared_ptr &Users::getSalt() const noexcept { return _salt; } -void Users::setSalt(const std::string &salt) noexcept +void Users::setSalt(const std::string &pSalt) noexcept { - _salt = std::make_shared(salt); + _salt = std::make_shared(pSalt); _dirtyFlag[7] = true; } -void Users::setSalt(std::string &&salt) noexcept +void Users::setSalt(std::string &&pSalt) noexcept { - _salt = std::make_shared(std::move(salt)); + _salt = std::make_shared(std::move(pSalt)); _dirtyFlag[7] = true; } @@ -266,9 +266,9 @@ const std::shared_ptr &Users::getAdmin() const noexcept { return _admin; } -void Users::setAdmin(const bool &admin) noexcept +void Users::setAdmin(const bool &pAdmin) noexcept { - _admin = std::make_shared(admin); + _admin = std::make_shared(pAdmin); _dirtyFlag[8] = true; } diff --git a/orm_lib/tests/Users.h b/orm_lib/tests/Users.h index 301000da..8d59947e 100644 --- a/orm_lib/tests/Users.h +++ b/orm_lib/tests/Users.h @@ -31,15 +31,15 @@ class Users public: struct Cols { - static const std::string user_id; - static const std::string user_name; - static const std::string password; - static const std::string org_name; - static const std::string signature; - static const std::string avatar_id; - static const std::string id; - static const std::string salt; - static const std::string admin; + static const std::string _user_id; + static const std::string _user_name; + static const std::string _password; + static const std::string _org_name; + static const std::string _signature; + static const std::string _avatar_id; + static const std::string _id; + static const std::string _salt; + static const std::string _admin; }; const static int primaryKeyNumber; @@ -59,8 +59,8 @@ class Users /// empty shared_ptr object if the column is null const std::shared_ptr &getUserId() const noexcept; /// Set the value of the column user_id - void setUserId(const std::string &userId) noexcept; - void setUserId(std::string &&userId) noexcept; + void setUserId(const std::string &pUserId) noexcept; + void setUserId(std::string &&pUserId) noexcept; /** For column user_name */ /// Get the value of the column user_name, returns the default value if the @@ -70,8 +70,8 @@ class Users /// empty shared_ptr object if the column is null const std::shared_ptr &getUserName() const noexcept; /// Set the value of the column user_name - void setUserName(const std::string &userName) noexcept; - void setUserName(std::string &&userName) noexcept; + void setUserName(const std::string &pUserName) noexcept; + void setUserName(std::string &&pUserName) noexcept; /** For column password */ /// Get the value of the column password, returns the default value if the @@ -81,8 +81,8 @@ class Users /// empty shared_ptr object if the column is null const std::shared_ptr &getPassword() const noexcept; /// Set the value of the column password - void setPassword(const std::string &password) noexcept; - void setPassword(std::string &&password) noexcept; + void setPassword(const std::string &pPassword) noexcept; + void setPassword(std::string &&pPassword) noexcept; /** For column org_name */ /// Get the value of the column org_name, returns the default value if the @@ -92,8 +92,8 @@ class Users /// empty shared_ptr object if the column is null const std::shared_ptr &getOrgName() const noexcept; /// Set the value of the column org_name - void setOrgName(const std::string &orgName) noexcept; - void setOrgName(std::string &&orgName) noexcept; + void setOrgName(const std::string &pOrgName) noexcept; + void setOrgName(std::string &&pOrgName) noexcept; /** For column signature */ /// Get the value of the column signature, returns the default value if the @@ -103,8 +103,8 @@ class Users /// empty shared_ptr object if the column is null const std::shared_ptr &getSignature() const noexcept; /// Set the value of the column signature - void setSignature(const std::string &signature) noexcept; - void setSignature(std::string &&signature) noexcept; + void setSignature(const std::string &pSignature) noexcept; + void setSignature(std::string &&pSignature) noexcept; /** For column avatar_id */ /// Get the value of the column avatar_id, returns the default value if the @@ -114,8 +114,8 @@ class Users /// empty shared_ptr object if the column is null const std::shared_ptr &getAvatarId() const noexcept; /// Set the value of the column avatar_id - void setAvatarId(const std::string &avatarId) noexcept; - void setAvatarId(std::string &&avatarId) noexcept; + void setAvatarId(const std::string &pAvatarId) noexcept; + void setAvatarId(std::string &&pAvatarId) noexcept; /** For column id */ /// Get the value of the column id, returns the default value if the column @@ -133,8 +133,8 @@ class Users /// empty shared_ptr object if the column is null const std::shared_ptr &getSalt() const noexcept; /// Set the value of the column salt - void setSalt(const std::string &salt) noexcept; - void setSalt(std::string &&salt) noexcept; + void setSalt(const std::string &pSalt) noexcept; + void setSalt(std::string &&pSalt) noexcept; /** For column admin */ /// Get the value of the column admin, returns the default value if the @@ -144,7 +144,7 @@ class Users /// empty shared_ptr object if the column is null const std::shared_ptr &getAdmin() const noexcept; /// Set the value of the column admin - void setAdmin(const bool &admin) noexcept; + void setAdmin(const bool &pAdmin) noexcept; static size_t getColumnNumber() noexcept { @@ -184,6 +184,5 @@ class Users static const std::vector _metaData; bool _dirtyFlag[9] = {false}; }; - } // namespace postgres } // namespace drogon_model