<%inc#include "create_model.h" using namespace drogon_ctl; %> /** * * {{className}}.cc * DO NOT EDIT. This file is generated by drogon_ctl * */ #include "{{className}}.h" #include #include <%c++ auto cols=@@.get>("columns"); auto className=@@.get("className"); %> using namespace drogon_model::{{dbName}}; <%c++for(auto col:cols){ %> const std::string {{className}}::Cols::<%c++$$< = "<%c++$$<"; <%c++ }%> <%c++if(@@.get("hasPrimaryKey")<=1){%> const std::string {{className}}::primaryKeyName = "{{primaryKeyName}}"; <%c++}else{%> const std::vector {{className}}::primaryKeyName = {<%c++ auto pkName=@@.get>("primaryKeyName"); for(size_t i=0;i}; <%c++}%> <%c++ if(@@.get("hasPrimaryKey",0)>0){%> const bool {{className}}::hasPrimaryKey = true; <%c++ }else{%> const bool {{className}}::hasPrimaryKey = false; <%c++}%> const std::string {{className}}::tableName = "{{tableName}}"; const std::vector {{className}}::_metaData={ <%c++for(size_t i=0;i }; const std::string &{{className}}::getColumnName(size_t index) noexcept(false) { assert(index < _metaData.size()); return _metaData[index]._colName; } {{className}}::{{className}}(const Row &r) noexcept { <%c++ for(auto col:cols) { if(col._colType.empty()) continue; %> if(!r["<%c++$$<"].isNull()) { <%c++ if(col._colDatabaseType=="date") { $$<<" auto daysStr = r[\""<();\n"; $$<<" struct tm stm;\n"; $$<<" memset(&stm,0,sizeof(stm));\n"; $$<<" strptime(daysStr.c_str(),\"%Y-%m-%d\",&stm);\n"; $$<<" long t = timelocal(&stm);\n"; // $$<<" _"<(::trantor::Date(946656000000000).after(daysNum*86400));\n"; $$<<" _"<(t*1000000);\n"; $$<<" }\n"; continue; } else if(col._colDatabaseType.find("timestamp")!=std::string::npos||col._colDatabaseType.find("datetime")!=std::string::npos) { $$<<" auto timeStr = r[\""<();\n"; $$<<" struct tm stm;\n"; $$<<" memset(&stm,0,sizeof(stm));\n"; $$<<" auto p = strptime(timeStr.c_str(),\"%Y-%m-%d %H:%M:%S\",&stm);\n"; $$<<" size_t t = timelocal(&stm);\n"; $$<<" size_t decimalNum = 0;\n"; $$<<" if(*p=='.')\n"; $$<<" {\n"; $$<<" std::string decimals(p+1,&timeStr[timeStr.length()]);\n"; $$<<" while(decimals.length()<6)\n"; $$<<" {\n"; $$<<" decimals += \"0\";\n"; $$<<" }\n"; $$<<" decimalNum = (size_t)atol(decimals.c_str());\n"; $$<<" }\n"; // $$<<" _"<(::trantor::Date(946656000000000).after(daysNum*86400));\n"; $$<<" _"<(t*1000000+decimalNum);\n"; $$<<" }\n"; continue; } else if(col._colDatabaseType=="bytea") { $$<<" auto str = r[\""<();\n"; $$<<" if(str.length()>=2&&\n"; $$<<" str[0]=='\\\\'&&str[1]=='x')\n"; $$<<" {\n"; $$<<" auto binStr=drogon::hexToBinaryString(str.c_str()+2,str.length()-2);\n"; $$<<" _"<>((char *)binStr.data(),(char *)binStr.data()+binStr.length());\n"; $$<<" }\n"; $$<<" }\n"; continue; } %> _<%c++$$<=std::make_shared<<%c++$$<>(r["<%c++$$<"].as<<%c++$$<>()); } <%c++ } %> } <%c++ for(size_t i=0;i") { $$<<"std::string "<data(),_"<size());\n"; $$<<" return defaultValue;\n"; $$<<"}\n"; } $$<<"std::shared_ptr "<("<("<(std::move("<") { $$<<"void "<>("<("hasPrimaryKey")==1) { $$<<"const typename "<("rdbms")=="postgresql") { $$<<"void "<("rdbms")=="mysql") { $$<<"void "<(id);\n"; break; } } $$<<"}\n"; } if(@@.get("hasPrimaryKey")>1) { $$<<"typename "<("hasPrimaryKey")) $$<<","; } } $$<<");\n"; $$<<"}\n"; } %> const std::vector &{{className}}::insertColumns() noexcept { static const std::vector _inCols={ <%c++for(size_t i=0;i }; return _inCols; } void {{className}}::outputArgs(drogon::orm::internal::SqlBinder &binder) const { <%c++for(auto col:cols){ if(!col._isAutoVal&&!col._colType.empty()) { %> if(get<%c++$$<()) { binder << getValueOf<%c++$$<(); } else { binder << nullptr; } <%c++ } } %> } const std::vector {{className}}::updateColumns() const { std::vector ret; for(size_t i=0;i if(_dirtyFlag[<%c++$$<]) { if(get<%c++$$<()) { binder << getValueOf<%c++$$<(); } else { binder << nullptr; } } <%c++ } %> } Json::Value {{className}}::toJson() const { Json::Value ret; <%c++for(auto col:cols){%> if(get<%c++$$<()) { <%c++if(col._colDatabaseType=="date"){%> ret["<%c++$$<"]=get<%c++$$<()->toDbStringLocal(); <%c++}else if(col._colDatabaseType.find("timestamp")!=std::string::npos||col._colDatabaseType.find("datetime")!=std::string::npos){%> ret["<%c++$$<"]=get<%c++$$<()->toDbStringLocal(); <%c++}else if(col._colDatabaseType=="bytea"||col._colDatabaseType.find("blob")!=std::string::npos){%> ret["<%c++$$<"]=drogon::base64Encode((const unsigned char *)get<%c++$$<()->data(),get<%c++$$<()->size()); <%c++}else if(col._colType=="int64_t"){%> ret["<%c++$$<"]=(Json::Int64)getValueOf<%c++$$<(); <%c++}else if(col._colType=="uint64_t"){%> ret["<%c++$$<"]=(Json::UInt64)getValueOf<%c++$$<(); <%c++}else{%> ret["<%c++$$<"]=getValueOf<%c++$$<(); <%c++}%> } else { ret["<%c++$$<"]=Json::Value(); } <%c++ }%> return ret; }