Skip to content

Commit

Permalink
Merge branch 'drogonframework:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mowangshuying authored Mar 29, 2024
2 parents 66eb97f + 9f28726 commit 2d818e5
Show file tree
Hide file tree
Showing 160 changed files with 1,204 additions and 891 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertNewlineAtEOF: true
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,25 @@ jobs:
- name: Install dos2unix
run: sudo apt-get install -y dos2unix

- name: Install clang-format-17
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x ./llvm.sh
sudo ./llvm.sh 17
sudo apt-get install -y clang-format-17
- name: Check formatting
run: ./format.sh && git diff --exit-code
env:
CLANG_FORMAT: clang-format-17

cpplint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Install cpplint
run: pip install cpplint

- name: Run lint
run: cpplint --recursive .
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CMAKE_DEPENDENT_OPTION(USE_SPDLOG "Allow using the spdlog logging library" OFF "

set(DROGON_MAJOR_VERSION 1)
set(DROGON_MINOR_VERSION 9)
set(DROGON_PATCH_VERSION 2)
set(DROGON_PATCH_VERSION 3)
set(DROGON_VERSION
${DROGON_MAJOR_VERSION}.${DROGON_MINOR_VERSION}.${DROGON_PATCH_VERSION})
set(DROGON_VERSION_STRING "${DROGON_VERSION}")
Expand Down
35 changes: 35 additions & 0 deletions CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Stop searching for additional config files.
set noparent

exclude_files=trantor
exclude_files=build

# Use non-const reference rather than a pointer.
filter=-runtime/references

# CHECK macros are from Drogon, not Google Test.
filter=-readability/check

# Don't warn about the use of C++11 features.
filter=-build/c++11

filter=-build/include_subdir

# We prioritize clang-format for now.
filter=-whitespace

# We don't require a username in TODO comments.
filter=-readability/todo

# TODO: Fix these.
filter=-legal/copyright
filter=-build/namespaces
filter=-build/include
filter=-build/include_what_you_use
filter=-runtime/explicit
filter=-runtime/string
filter=-runtime/int
filter=-readability/casting
filter=-readability/braces
filter=-readability/fn_size
filter=-runtime/threadsafe_fn
50 changes: 49 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,52 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## [1.9.3] - 2024-02-09

### API changes list

- Added getParameter() and getOptionalParameter().

- Change drogon::MultiPartParser's parameters data type.

- Use std::string_view for WebSockets.

### Changed

- Add support for gentoo linux, dev-db/mariadb contains mysql.

- Introduce cpplint to the CI.

- Enable readability/alt_tokens for cpplint.

- Use clang-format-17.

- Add newline at EOF.

- Enable readability/inheritance for cpplint.

- Enable build/explicit_make_pair for cpplint.

- Enable build/include_order for cpplint.

- Enable build/header_guard for cpplint.

- Enable build/storage_class for cpplint.

- Enable readability/multiline_string for cpplint.

- Alias the safe hashmap template.

- Simplify traits in utils.

- Enhancement: extend drogon::ContentType for file handling.

### Fixed

- Fix a wrong place of return.

- Fix drogon::util::fromString().

## [1.9.2] - 2024-01-18

### API changes list
Expand Down Expand Up @@ -1575,7 +1621,9 @@ All notable changes to this project will be documented in this file.

## [1.0.0-beta1] - 2019-06-11

[Unreleased]: https://github.com/an-tao/drogon/compare/v1.9.2...HEAD
[Unreleased]: https://github.com/an-tao/drogon/compare/v1.9.3...HEAD

[1.9.3]: https://github.com/an-tao/drogon/compare/v1.9.2...v1.9.3

[1.9.2]: https://github.com/an-tao/drogon/compare/v1.9.1...v1.9.2

Expand Down
4 changes: 3 additions & 1 deletion cmake/templates/version.h.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#define MAJOR @DROGON_MAJOR_VERSION@
#define MINOR @DROGON_MINOR_VERSION@
#define PATCH @DROGON_PATCH_VERSION@
#define DROGON_VERSION "@DROGON_VERSION_STRING@"
#define DROGON_VERSION_SHA1 "@GIT_SHA1@"
#define DROGON_VERSION_SHA1 "@GIT_SHA1@"
2 changes: 1 addition & 1 deletion drogon_ctl/create_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,4 @@ void create_controller::createARestfulController(const std::string &className,
<< std::endl;
std::cout << "File name: " << ctlName << ".h and " << ctlName << ".cc"
<< std::endl;
}
}
70 changes: 38 additions & 32 deletions drogon_ctl/create_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ void create_model::createModelClassFromPG(
data["schema"] = schema;
}
std::vector<ColumnInfo> cols;
*client << "SELECT * \
FROM information_schema.columns \
WHERE table_schema = $1 \
AND table_name = $2"
*client << "SELECT * "
"FROM information_schema.columns "
"WHERE table_schema = $1 "
"AND table_name = $2"
<< schema << tableName << Mode::Blocking >>
[&](const Result &r) {
if (r.size() == 0)
Expand Down Expand Up @@ -284,14 +284,14 @@ void create_model::createModelClassFromPG(
exit(1);
};
size_t pkNumber = 0;
*client << "SELECT \
pg_constraint.conname AS pk_name,\
pg_constraint.conkey AS pk_vector \
FROM pg_constraint \
INNER JOIN pg_class ON pg_constraint.conrelid = pg_class.oid \
WHERE \
pg_class.relname = $1 \
AND pg_constraint.contype = 'p'"
*client << "SELECT "
"pg_constraint.conname AS pk_name,"
"pg_constraint.conkey AS pk_vector "
"FROM pg_constraint "
"INNER JOIN pg_class ON pg_constraint.conrelid = pg_class.oid "
"WHERE "
"pg_class.relname = $1 "
"AND pg_constraint.contype = 'p'"
<< tableName << Mode::Blocking >>
[&](bool isNull,
const std::string &pkName,
Expand All @@ -308,16 +308,18 @@ void create_model::createModelClassFromPG(
data["hasPrimaryKey"] = (int)pkNumber;
if (pkNumber == 1)
{
*client << "SELECT \
pg_attribute.attname AS colname,\
pg_type.typname AS typename,\
pg_constraint.contype AS contype \
FROM pg_constraint \
INNER JOIN pg_class ON pg_constraint.conrelid = pg_class.oid \
INNER JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid \
AND pg_attribute.attnum = pg_constraint.conkey [ 1 ] \
INNER JOIN pg_type ON pg_type.oid = pg_attribute.atttypid \
WHERE pg_class.relname = $1 and pg_constraint.contype='p'"
*client << "SELECT "
"pg_attribute.attname AS colname,"
"pg_type.typname AS typename,"
"pg_constraint.contype AS contype "
"FROM pg_constraint "
"INNER JOIN pg_class ON pg_constraint.conrelid = "
"pg_class.oid "
"INNER JOIN pg_attribute ON pg_attribute.attrelid = "
"pg_class.oid "
"AND pg_attribute.attnum = pg_constraint.conkey [ 1 ] "
"INNER JOIN pg_type ON pg_type.oid = pg_attribute.atttypid "
"WHERE pg_class.relname = $1 and pg_constraint.contype='p'"
<< tableName << Mode::Blocking >>
[&](bool isNull,
const std::string &colName,
Expand Down Expand Up @@ -345,16 +347,20 @@ void create_model::createModelClassFromPG(
std::vector<std::string> pkNames, pkTypes, pkValNames;
for (size_t i = 1; i <= pkNumber; ++i)
{
*client << "SELECT \
pg_attribute.attname AS colname,\
pg_type.typname AS typename,\
pg_constraint.contype AS contype \
FROM pg_constraint \
INNER JOIN pg_class ON pg_constraint.conrelid = pg_class.oid \
INNER JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid \
AND pg_attribute.attnum = pg_constraint.conkey [ $1 ] \
INNER JOIN pg_type ON pg_type.oid = pg_attribute.atttypid \
WHERE pg_class.relname = $2 and pg_constraint.contype='p'"
*client << "SELECT "
"pg_attribute.attname AS colname,"
"pg_type.typname AS typename,"
"pg_constraint.contype AS contype "
"FROM pg_constraint "
"INNER JOIN pg_class ON pg_constraint.conrelid = "
"pg_class.oid "
"INNER JOIN pg_attribute ON pg_attribute.attrelid = "
"pg_class.oid "
"AND pg_attribute.attnum = pg_constraint.conkey [ $1 ] "
"INNER JOIN pg_type ON pg_type.oid = "
"pg_attribute.atttypid "
"WHERE pg_class.relname = $2 and "
"pg_constraint.contype='p'"
<< (int)i << tableName << Mode::Blocking >>
[&](bool isNull, std::string colName, const std::string &type) {
if (isNull)
Expand Down
16 changes: 8 additions & 8 deletions drogon_ctl/templates/model_cc.csp
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ void [[className]]::updateByJson(const Json::Value &pJson) noexcept(false)
{
$$<<"const "<<col.colType_<<" &"<<className<<"::getValueOf"<<col.colTypeName_<<"() const noexcept\n";
$$<<"{\n";
$$<<" const static "<<col.colType_<<" defaultValue = "<<col.colType_<<"();\n";
$$<<" static const "<<col.colType_<<" defaultValue = "<<col.colType_<<"();\n";
$$<<" if("<<col.colValName_<<"_)\n";
$$<<" return *"<<col.colValName_<<"_;\n";
$$<<" return defaultValue;\n";
Expand All @@ -984,7 +984,7 @@ void [[className]]::updateByJson(const Json::Value &pJson) noexcept(false)
{
$$<<"std::string "<<className<<"::getValueOf"<<col.colTypeName_<<"AsString() const noexcept\n";
$$<<"{\n";
$$<<" const static std::string defaultValue = std::string();\n";
$$<<" static const std::string defaultValue = std::string();\n";
$$<<" if("<<col.colValName_<<"_)\n";
$$<<" return std::string("<<col.colValName_<<"_->data(),"<<col.colValName_<<"_->size());\n";
$$<<" return defaultValue;\n";
Expand Down Expand Up @@ -1584,7 +1584,7 @@ for(auto &relationship : relationships)
{
%>
{%relationshipClassName%} [[className]]::get{%alias%}(const DbClientPtr &clientPtr) const {
const static std::string sql = "select * from {%name%} where {%relationship.targetKey()%} = <%c++
static const std::string sql = "select * from {%name%} where {%relationship.targetKey()%} = <%c++
if(rdbms=="postgresql")
{
$$<<"$1";
Expand Down Expand Up @@ -1615,7 +1615,7 @@ void [[className]]::get{%alias%}(const DbClientPtr &clientPtr,
{%indentStr%} {%alind%} const std::function<void({%relationshipClassName%})> &rcb,
{%indentStr%} {%alind%} const ExceptionCallback &ecb) const
{
const static std::string sql = "select * from {%name%} where {%relationship.targetKey()%} = <%c++
static const std::string sql = "select * from {%name%} where {%relationship.targetKey()%} = <%c++
if(rdbms=="postgresql")
{
$$<<"$1";
Expand Down Expand Up @@ -1648,7 +1648,7 @@ void [[className]]::get{%alias%}(const DbClientPtr &clientPtr,
{
%>
std::vector<{%relationshipClassName%}> [[className]]::get{%alias%}(const DbClientPtr &clientPtr) const {
const static std::string sql = "select * from {%name%} where {%relationship.targetKey()%} = <%c++
static const std::string sql = "select * from {%name%} where {%relationship.targetKey()%} = <%c++
if(rdbms=="postgresql")
{
$$<<"$1";
Expand Down Expand Up @@ -1677,7 +1677,7 @@ void [[className]]::get{%alias%}(const DbClientPtr &clientPtr,
{%indentStr%} {%alind%} const std::function<void(std::vector<{%relationshipClassName%}>)> &rcb,
{%indentStr%} {%alind%} const ExceptionCallback &ecb) const
{
const static std::string sql = "select * from {%name%} where {%relationship.targetKey()%} = <%c++
static const std::string sql = "select * from {%name%} where {%relationship.targetKey()%} = <%c++
if(rdbms=="postgresql")
{
$$<<"$1";
Expand Down Expand Up @@ -1709,7 +1709,7 @@ void [[className]]::get{%alias%}(const DbClientPtr &clientPtr,
auto &pivotTargetKey=relationship.pivotTable().targetKey();
%>
std::vector<std::pair<{%relationshipClassName%},{%pivotTableClassName%}>> [[className]]::get{%alias%}(const DbClientPtr &clientPtr) const {
const static std::string sql = "select * from {%name%},{%pivotTableName%} where {%pivotTableName%}.{%pivotOriginalKey%} = <%c++
static const std::string sql = "select * from {%name%},{%pivotTableName%} where {%pivotTableName%}.{%pivotOriginalKey%} = <%c++
if(rdbms=="postgresql")
{
$$<<"$1";
Expand Down Expand Up @@ -1739,7 +1739,7 @@ void [[className]]::get{%alias%}(const DbClientPtr &clientPtr,
{%indentStr%} {%alind%} const std::function<void(std::vector<std::pair<{%relationshipClassName%},{%pivotTableClassName%}>>)> &rcb,
{%indentStr%} {%alind%} const ExceptionCallback &ecb) const
{
const static std::string sql = "select * from {%name%},{%pivotTableName%} where {%pivotTableName%}.{%pivotOriginalKey%} = <%c++
static const std::string sql = "select * from {%name%},{%pivotTableName%} where {%pivotTableName%}.{%pivotOriginalKey%} = <%c++
if(rdbms=="postgresql")
{
$$<<"$1";
Expand Down
10 changes: 5 additions & 5 deletions drogon_ctl/templates/model_h.csp
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ auto cols=@@.get<std::vector<ColumnInfo>>("columns");
%>
};

const static int primaryKeyNumber;
const static std::string tableName;
const static bool hasPrimaryKey;
static const int primaryKeyNumber;
static const std::string tableName;
static const bool hasPrimaryKey;
<%c++if(@@.get<int>("hasPrimaryKey")<=1){%>
const static std::string primaryKeyName;
static const std::string primaryKeyName;
<%c++if(!@@.get<std::string>("primaryKeyType").empty()){%>
using PrimaryKeyType = [[primaryKeyType]];
const PrimaryKeyType &getPrimaryKey() const;
Expand All @@ -108,7 +108,7 @@ auto cols=@@.get<std::vector<ColumnInfo>>("columns");
typelist += ",";
}
%>
const static std::vector<std::string> primaryKeyName;
static const std::vector<std::string> primaryKeyName;
using PrimaryKeyType = std::tuple<{%typelist%}>;//<%c++
auto pkName=@@.get<std::vector<std::string>>("primaryKeyName");
for(size_t i=0;i<pkName.size();i++)
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark/BenchmarkCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using namespace drogon;
class BenchmarkCtrl : public drogon::HttpSimpleController<BenchmarkCtrl>
{
public:
virtual void asyncHandleHttpRequest(
void asyncHandleHttpRequest(
const HttpRequestPtr &req,
std::function<void(const HttpResponsePtr &)> &&callback) override;
PATH_LIST_BEGIN
Expand Down
4 changes: 2 additions & 2 deletions examples/benchmark/JsonCtrl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ void JsonCtrl::asyncHandleHttpRequest(
{
Json::Value ret;
ret["message"] = "Hello, World!";
auto resp = HttpResponse::newHttpJsonResponse(ret);
auto resp = HttpResponse::newHttpJsonResponse(std::move(ret));
callback(resp);
}
}
2 changes: 1 addition & 1 deletion examples/benchmark/JsonCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using namespace drogon;
class JsonCtrl : public drogon::HttpSimpleController<JsonCtrl>
{
public:
virtual void asyncHandleHttpRequest(
void asyncHandleHttpRequest(
const HttpRequestPtr &req,
std::function<void(const HttpResponsePtr &)> &&callback) override;
PATH_LIST_BEGIN
Expand Down
2 changes: 1 addition & 1 deletion examples/file_upload/file_upload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ int main()
.setUploadPath("./uploads")
.addListener("127.0.0.1", 8848)
.run();
}
}
2 changes: 1 addition & 1 deletion examples/helloworld/HelloController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ class SayHello : public HttpController<SayHello>
"Hi there, this is another hello from the SayHello Controller");
callback(resp);
}
};
};
Loading

0 comments on commit 2d818e5

Please sign in to comment.