Modify the drogon_ctl

This commit is contained in:
antao 2018-12-07 19:08:17 +08:00
parent d242b05cb9
commit 71faac9fb2
4 changed files with 27 additions and 20 deletions

View File

@ -38,7 +38,7 @@ struct ColumnInfo
std::string _colType;
std::string _colDatabaseType;
std::string _dbType;
ssize_t _colLength = -1;
ssize_t _colLength = 0;
size_t _index = 0;
bool _isAutoVal = false;
bool _isPrimaryKey = false;

View File

@ -18,6 +18,8 @@
#include <fstream>
#include <string>
#include <algorithm>
#include <regex>
static const std::string cxx_include = "<%inc";
static const std::string cxx_end = "%>";
static const std::string cxx_lang = "<%c++";
@ -362,6 +364,11 @@ void create_view::newViewSourceFile(std::ofstream &file, const std::string &clas
while (infile.getline(line, sizeof(line)))
{
buffer = line;
if (buffer.length() > 0)
{
std::regex re("\\{%[ \\t]*([^ \\t%]*)[^%]*%\\}");
buffer = std::regex_replace(buffer, re, "<%c++$$$$<<$1;%>");
}
parseLine(file, buffer, streamName, viewDataName, cxx_flag);
}

View File

@ -20,7 +20,7 @@ using namespace drogon_model::{{dbName}};
<%c++for(auto col:cols){
%>
const std::string {{className}}::Cols::<%c++$$<<col._colName;%> = "<%c++$$<<col._colName;%>";
const std::string {{className}}::Cols::{%col._colName%} = "{%col._colName%}";
<%c++
}%>
<%c++if(@@.get<int>("hasPrimaryKey")<=1){%>
@ -66,7 +66,7 @@ const std::string &{{className}}::getColumnName(size_t index) noexcept(false)
if(col._colType.empty())
continue;
%>
if(!r["<%c++$$<<col._colName;%>"].isNull())
if(!r["{%col._colName%}"].isNull())
{
<%c++
if(col._colDatabaseType=="date")
@ -116,7 +116,7 @@ const std::string &{{className}}::getColumnName(size_t index) noexcept(false)
continue;
}
%>
_<%c++$$<<col._colValName;%>=std::make_shared<<%c++$$<<col._colType;%>>(r["<%c++$$<<col._colName;%>"].as<<%c++$$<<col._colType;%>>());
_{%col._colValName%}=std::make_shared<{%col._colType%}>(r["{%col._colName%}"].as<{%col._colType%}>());
}
<%c++
}
@ -257,9 +257,9 @@ void {{className}}::outputArgs(drogon::orm::internal::SqlBinder &binder) const
if(!col._isAutoVal&&!col._colType.empty())
{
%>
if(get<%c++$$<<col._colTypeName;%>())
if(get{%col._colTypeName%}())
{
binder << getValueOf<%c++$$<<col._colTypeName;%>();
binder << getValueOf{%col._colTypeName%}();
}
else
{
@ -293,11 +293,11 @@ void {{className}}::updateArgs(drogon::orm::internal::SqlBinder &binder) const
if(col._colType.empty()||col._isAutoVal)
continue;
%>
if(_dirtyFlag[<%c++$$<<i;%>])
if(_dirtyFlag[{%i%}])
{
if(get<%c++$$<<col._colTypeName;%>())
if(get{%col._colTypeName%}())
{
binder << getValueOf<%c++$$<<col._colTypeName;%>();
binder << getValueOf{%col._colTypeName%}();
}
else
{
@ -312,25 +312,25 @@ Json::Value {{className}}::toJson() const
{
Json::Value ret;
<%c++for(auto col:cols){%>
if(get<%c++$$<<col._colTypeName;%>())
if(get{%col._colTypeName%}())
{
<%c++if(col._colDatabaseType=="date"){%>
ret["<%c++$$<<col._colName;%>"]=get<%c++$$<<col._colTypeName;%>()->toDbStringLocal();
ret["{%col._colName%}"]=get{%col._colTypeName%}()->toDbStringLocal();
<%c++}else if(col._colDatabaseType.find("timestamp")!=std::string::npos||col._colDatabaseType.find("datetime")!=std::string::npos){%>
ret["<%c++$$<<col._colName;%>"]=get<%c++$$<<col._colTypeName;%>()->toDbStringLocal();
ret["{%col._colName%}"]=get{%col._colTypeName%}()->toDbStringLocal();
<%c++}else if(col._colDatabaseType=="bytea"||col._colDatabaseType.find("blob")!=std::string::npos){%>
ret["<%c++$$<<col._colName;%>"]=drogon::base64Encode((const unsigned char *)get<%c++$$<<col._colTypeName;%>()->data(),get<%c++$$<<col._colTypeName;%>()->size());
ret["{%col._colName%}"]=drogon::base64Encode((const unsigned char *)get{%col._colTypeName%}()->data(),get{%col._colTypeName%}()->size());
<%c++}else if(col._colType=="int64_t"){%>
ret["<%c++$$<<col._colName;%>"]=(Json::Int64)getValueOf<%c++$$<<col._colTypeName;%>();
ret["{%col._colName%}"]=(Json::Int64)getValueOf{%col._colTypeName%}();
<%c++}else if(col._colType=="uint64_t"){%>
ret["<%c++$$<<col._colName;%>"]=(Json::UInt64)getValueOf<%c++$$<<col._colTypeName;%>();
ret["{%col._colName%}"]=(Json::UInt64)getValueOf{%col._colTypeName%}();
<%c++}else{%>
ret["<%c++$$<<col._colName;%>"]=getValueOf<%c++$$<<col._colTypeName;%>();
ret["{%col._colName%}"]=getValueOf{%col._colTypeName%}();
<%c++}%>
}
else
{
ret["<%c++$$<<col._colName;%>"]=Json::Value();
ret["{%col._colName%}"]=Json::Value();
}
<%c++
}%>

View File

@ -65,7 +65,7 @@ auto cols=@@.get<std::vector<ColumnInfo>>("columns");
}
%>
const static std::vector<std::string> primaryKeyName;
typedef std::tuple<<%c++$$<<typelist;%>> PrimaryKeyType;//<%c++
typedef std::tuple<{%typelist%}> PrimaryKeyType;//<%c++
auto pkName=@@.get<std::vector<std::string>>("primaryKeyName");
for(size_t i=0;i<pkName.size();i++)
{
@ -113,7 +113,7 @@ auto cols=@@.get<std::vector<ColumnInfo>>("columns");
}
%>
static size_t getColumnNumber() noexcept { return <%c++$$<<cols.size();%>; }
static size_t getColumnNumber() noexcept { return {% cols.size() %}; }
static const std::string &getColumnName(size_t index) noexcept(false);
Json::Value toJson() const;
@ -144,7 +144,7 @@ auto cols=@@.get<std::vector<ColumnInfo>>("columns");
const bool _notNull;
};
static const std::vector<MetaData> _metaData;
bool _dirtyFlag[<%c++$$<<cols.size();%>]={ false };
bool _dirtyFlag[{%cols.size()%}]={ false };
};
} // namespace {{dbName}}