mirror of
https://github.com/drogonframework/drogon.git
synced 2025-09-18 00:01:01 -04:00
Fix some bugs in creating models
This commit is contained in:
parent
d340e1cc10
commit
143b62b36b
@ -68,6 +68,7 @@ include_directories(${PostgreSQL_INCLUDE_DIR})
|
||||
message(STATUS "libpq inc path:" ${PostgreSQL_INCLUDE_DIR})
|
||||
link_libraries(${PostgreSQL_LIBRARIES})
|
||||
aux_source_directory(${PROJECT_SOURCE_DIR}/orm_lib/src/postgresql_impl DIR_SRCS)
|
||||
set(USE_ORM TRUE)
|
||||
endif()
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "")
|
||||
@ -137,10 +138,15 @@ endif ()
|
||||
|
||||
SET(CMAKE_INSTALL_PREFIX /usr/local)
|
||||
|
||||
#Installation
|
||||
install(TARGETS drogon DESTINATION lib)
|
||||
|
||||
file(GLOB drogon_headers "${CMAKE_CURRENT_SOURCE_DIR}/lib/inc/drogon/*.h")
|
||||
install(FILES ${drogon_headers} DESTINATION include/drogon)
|
||||
if(USE_ORM)
|
||||
file(GLOB orm_headers "${CMAKE_CURRENT_SOURCE_DIR}/orm_lib/inc/drogon/orm/*.h")
|
||||
install(FILES ${orm_headers} DESTINATION include/drogon/orm)
|
||||
endif()
|
||||
file(GLOB drogon_util_headers "${CMAKE_CURRENT_SOURCE_DIR}/lib/inc/drogon/utils/*.h")
|
||||
install(FILES ${drogon_util_headers}
|
||||
DESTINATION include/drogon/utils)
|
||||
|
@ -67,6 +67,11 @@ static void newConfigFile(std::ofstream &configFile)
|
||||
auto templ=DrTemplateBase::newTemplate("config");
|
||||
configFile << templ->genText();
|
||||
}
|
||||
static void newModelConfigFile(std::ofstream &configFile)
|
||||
{
|
||||
auto templ = DrTemplateBase::newTemplate("model_json");
|
||||
configFile << templ->genText();
|
||||
}
|
||||
void create_project::createProject(const std::string &projectName)
|
||||
{
|
||||
|
||||
@ -88,6 +93,7 @@ void create_project::createProject(const std::string &projectName)
|
||||
mkdir("controllers", 0755);
|
||||
mkdir("filters", 0755);
|
||||
mkdir("build", 0755);
|
||||
mkdir("models", 0755);
|
||||
mkdir("cmake_modules", 0755);
|
||||
std::ofstream jsonFile("cmake_modules/FindJsoncpp.cmake", std::ofstream::out);
|
||||
newJsonFindFile(jsonFile);
|
||||
@ -98,4 +104,6 @@ void create_project::createProject(const std::string &projectName)
|
||||
newGitIgFile(gitFile);
|
||||
std::ofstream configFile("config.json", std::ofstream::out);
|
||||
newConfigFile(configFile);
|
||||
std::ofstream modelConfigFile("models/model.json", std::ofstream::out);
|
||||
newModelConfigFile(modelConfigFile);
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ endif()
|
||||
AUX_SOURCE_DIRECTORY(./ SRC_DIR)
|
||||
AUX_SOURCE_DIRECTORY(controllers CTL_SRC)
|
||||
AUX_SOURCE_DIRECTORY(filters FILTER_SRC)
|
||||
AUX_SOURCE_DIRECTORY(models MODEL_SRC)
|
||||
|
||||
FILE(GLOB SCP_LIST ${CMAKE_CURRENT_SOURCE_DIR}/views/*.csp)
|
||||
foreach(cspFile ${SCP_LIST})
|
||||
@ -77,4 +78,5 @@ foreach(cspFile ${SCP_LIST})
|
||||
set(VIEWSRC ${VIEWSRC} ${classname}.cc)
|
||||
endforeach()
|
||||
|
||||
add_executable({{ProjectName}} ${SRC_DIR} ${CTL_SRC} ${FILTER_SRC} ${VIEWSRC})
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_executable({{ProjectName}} ${SRC_DIR} ${CTL_SRC} ${FILTER_SRC} ${VIEWSRC} ${MODEL_SRC})
|
||||
|
@ -11,14 +11,14 @@ using namespace drogon_ctl;
|
||||
#include "{{className}}.h"
|
||||
#include <string>
|
||||
|
||||
using namespace drogon_model::{{dbname}};
|
||||
const std::string User::primaryKeyName = "{{priKeyName}}";
|
||||
using namespace drogon_model::{{dbName}};
|
||||
const std::string {{className}}::primaryKeyName = "{{priKeyName}}";
|
||||
<%c++ if(@@.get<bool>("hasPrimaryKey",false)){%>
|
||||
const bool User::hasPrimaryKey = true;
|
||||
const bool {{className}}::hasPrimaryKey = true;
|
||||
<%c++ }else{%>
|
||||
const bool User::hasPrimaryKey = false;
|
||||
const bool {{className}}::hasPrimaryKey = false;
|
||||
<%c++}%>
|
||||
const std::string User::tableName = "{{tableName}}";
|
||||
const std::string {{className}}::tableName = "{{tableName}}";
|
||||
<%c++
|
||||
auto cols=@@.get<std::vector<ColumnInfo>>("columns");
|
||||
auto className=@@.get<std::string>("className");
|
||||
@ -44,11 +44,11 @@ const std::string User::tableName = "{{tableName}}";
|
||||
{
|
||||
if(!col._colType.empty())
|
||||
{
|
||||
$$<<"const "<<col._colType<<" & "<<className<<"::getValueOf"<<col._colTypeName<<"(const "<<col._colType<<" &default) const noexcept\n";
|
||||
$$<<"const "<<col._colType<<" & "<<className<<"::getValueOf"<<col._colTypeName<<"(const "<<col._colType<<" &defaultValue) const noexcept\n";
|
||||
$$<<"{\n";
|
||||
$$<<" if(_"<<col._colValName<<")\n";
|
||||
$$<<" return *_"<<col._colValName<<";\n";
|
||||
$$<<" return default;\n";
|
||||
$$<<" return defaultValue;\n";
|
||||
$$<<"}\n";
|
||||
|
||||
|
||||
|
@ -13,6 +13,8 @@ using namespace drogon_ctl;
|
||||
#include <drogon/orm/Field.h>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
|
||||
using namespace drogon::orm;
|
||||
|
||||
namespace drogon_model
|
||||
@ -26,8 +28,11 @@ class {{className}}
|
||||
const static std::string primaryKeyName;
|
||||
const static bool hasPrimaryKey;
|
||||
const static std::string tableName;
|
||||
|
||||
<%c++if(!@@.get<std::string>("primaryKeyType").empty()){%>
|
||||
typedef {{primaryKeyType}} PrimaryKeyType;
|
||||
<%c++}else{%>
|
||||
typedef void PrimaryKeyType;
|
||||
<%c++}%>
|
||||
{{className}}(const Row &r) noexcept;
|
||||
|
||||
<%c++
|
||||
@ -37,7 +42,7 @@ class {{className}}
|
||||
$$<<" //For column "<<col._colName<<"\n";
|
||||
if(!col._colType.empty())
|
||||
{
|
||||
$$<<" const "<<col._colType<<" &getValueOf"<<col._colTypeName<<"(const "<<col._colType<<" &default="<<col._colType<<"()) const noexcept;\n";
|
||||
$$<<" const "<<col._colType<<" &getValueOf"<<col._colTypeName<<"(const "<<col._colType<<" &defaultValue="<<col._colType<<"()) const noexcept;\n";
|
||||
$$<<" std::shared_ptr<const "<<col._colType<<"> get"<<col._colTypeName<<"() const noexcept;\n";
|
||||
$$<<" void set"<<col._colTypeName<<"(const "<<col._colType<<" &"<<col._colValName<<") noexcept;\n";
|
||||
if(col._colType=="std::string")
|
||||
|
13
drogon_ctl/templates/model_json.csp
Normal file
13
drogon_ctl/templates/model_json.csp
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
//rdbms:server type, postgreSQL
|
||||
"rdbms":"postgreSQL",
|
||||
//host:server address,localhost by default;
|
||||
"host":"127.0.0.1",
|
||||
//port:server port, 5432 by default;
|
||||
"port":5432,
|
||||
//dbname:Database name;
|
||||
"dbname":"",
|
||||
"user":"",
|
||||
"passwd":"",
|
||||
"tables":[]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user