Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c451a4e
初始化duckdb的两种实现目录
weidqi Jul 3, 2025
35c3cfe
添加sqlite_api_wrapper源代码到工程,2025-07-03晚于沙特吉达
weidqi Jul 3, 2025
28f96d7
添加sqlite_wrapper源代码,编译通过
weidqi Jul 8, 2025
e03d948
初步实现了duckdb wrapper,有待进一步测试
weidqi Jul 12, 2025
cc5fae8
修改SqlBinder,增加对ClientType::DuckDB的处理逻辑
weidqi Jul 13, 2025
6c01a8a
Added comprehensive test cases.
weidqi Jul 13, 2025
5a85d8a
fixed some bug.
weidqi Aug 10, 2025
1dfad64
Lint
an-tao Aug 22, 2025
7abc38b
More lint
an-tao Aug 22, 2025
2db43f4
为 Drogon 框架添加 DuckDB 数据库支持,使用原生c api
weidqi Nov 19, 2025
cf42232
功能增强:DuckDB 配置参数灵活化支持
weidqi Nov 19, 2025
d171eda
Merge branch 'drogonframework:master' into duckdb-add-branch
weidqi Nov 25, 2025
b73a47e
同步主版本
weidqi Nov 25, 2025
20f9261
Update .gitignore
weidqi Nov 25, 2025
2505553
Update orm_lib/tests/db_test.cc
weidqi Nov 27, 2025
11ce913
Update orm_lib/src/DbClientImpl.cc
weidqi Nov 27, 2025
b1d0d89
Update orm_lib/src/duckdb_impl/DuckdbConnection.cc
weidqi Nov 27, 2025
72640f7
Update orm_lib/src/duckdb_impl/readme.md
weidqi Nov 27, 2025
6dabe7b
Update orm_lib/src/duckdb_impl/changelog.md
weidqi Nov 27, 2025
6599b0e
Update CMakeLists.txt
weidqi Nov 27, 2025
9076552
The reviewer's comments and suggestions have been incorporated.
weidqi Nov 27, 2025
c3174f9
Adjusted some settings to resolve a local build issue for: COMMAND $<…
weidqi Nov 27, 2025
ec22479
configure modify
weidqi Nov 27, 2025
fe1f72c
Remove trantor
weidqi Nov 27, 2025
0b0c449
DuckDB 避免连接打开失败时出现自线程 `EventLoopThread` 析构与后续堆损坏
weidqi Apr 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 63 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ project(drogon)

message(STATUS "compiler: " ${CMAKE_CXX_COMPILER_ID})


option(BUILD_CTL "Build drogon_ctl" ON)
option(BUILD_EXAMPLES "Build examples" ON)
option(BUILD_ORM "Build orm" ON)
Expand All @@ -20,6 +21,9 @@ CMAKE_DEPENDENT_OPTION(BUILD_POSTGRESQL "Build with postgresql support" ON "BUIL
CMAKE_DEPENDENT_OPTION(LIBPQ_BATCH_MODE "Use batch mode for libpq" ON "BUILD_POSTGRESQL" OFF)
CMAKE_DEPENDENT_OPTION(BUILD_MYSQL "Build with mysql support" ON "BUILD_ORM" OFF)
CMAKE_DEPENDENT_OPTION(BUILD_SQLITE "Build with sqlite3 support" ON "BUILD_ORM" OFF)
# Add DuckDB support
CMAKE_DEPENDENT_OPTION(BUILD_DUCKDB "Build with duckdb support" ON "BUILD_ORM" OFF)

CMAKE_DEPENDENT_OPTION(BUILD_REDIS "Build with redis support" ON "BUILD_ORM" OFF)
CMAKE_DEPENDENT_OPTION(USE_SPDLOG "Allow using the spdlog logging library" OFF "USE_SUBMODULE" OFF)

Expand Down Expand Up @@ -461,6 +465,50 @@ if (BUILD_SQLITE)
endif (DROGON_FOUND_SQLite3)
endif (BUILD_SQLITE)

# Add DuckDB support
if (BUILD_DUCKDB)
# Find DuckDB library
find_package(DuckDB QUIET)
if(NOT DuckDB_FOUND)
# Try to find DuckDB manually
find_library(DUCKDB_LIBRARY
NAMES duckdb
PATHS /usr/lib /usr/local/lib /opt/homebrew/lib
)
find_path(DUCKDB_INCLUDE_DIR
NAMES duckdb.h
PATHS /usr/include /usr/local/include /opt/homebrew/include
)

if(DUCKDB_LIBRARY AND DUCKDB_INCLUDE_DIR)
set(DuckDB_LIBRARIES ${DUCKDB_LIBRARY})
set(DuckDB_INCLUDE_DIRS ${DUCKDB_INCLUDE_DIR})
set(DuckDB_FOUND TRUE)
endif()
endif()
Comment on lines +472 to +488
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be handled in FindDuckDB.


if (DuckDB_FOUND)
message(STATUS "Ok! We find DuckDB!")
target_link_libraries(${PROJECT_NAME} PRIVATE ${DuckDB_LIBRARIES})
target_include_directories(${PROJECT_NAME} PRIVATE ${DuckDB_INCLUDE_DIRS})
set(DROGON_FOUND_DUCKDB TRUE)
set(DROGON_SOURCES
${DROGON_SOURCES}
orm_lib/src/duckdb_impl/DuckdbConnection.cc
orm_lib/src/duckdb_impl/DuckdbResultImpl.cc)
set(private_headers
${private_headers}
orm_lib/src/duckdb_impl/DuckdbConnection.h
orm_lib/src/duckdb_impl/DuckdbResultImpl.h)
else (DuckDB_FOUND)
message(STATUS "DuckDB was not found.")
set(DROGON_FOUND_DUCKDB FALSE)
endif (DuckDB_FOUND)
else (BUILD_DUCKDB)
set(DROGON_FOUND_DUCKDB FALSE)
endif (BUILD_DUCKDB)


if (BUILD_REDIS)
find_package(Hiredis)
if (Hiredis_FOUND)
Expand Down Expand Up @@ -524,15 +572,6 @@ if (BUILD_EXAMPLES)
endif (BUILD_EXAMPLES)

if (BUILD_CTL)
if (CMAKE_CROSSCOMPILING)
find_program(HOST_DROGON_CTL _drogon_ctl)
if (NOT HOST_DROGON_CTL)
message(FATAL_ERROR "_drogon_ctl not found on host system")
endif()
set(DROGON_CTL "${HOST_DROGON_CTL}")
else (CMAKE_CROSSCOMPILING)
set(DROGON_CTL "$<TARGET_FILE:_drogon_ctl>")
endif (CMAKE_CROSSCOMPILING)
add_subdirectory(drogon_ctl)
endif (BUILD_CTL)

Expand Down Expand Up @@ -622,7 +661,8 @@ set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD_REQUIRED ON)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF)
set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME Drogon)

if (pg_FOUND OR DROGON_FOUND_MYSQL OR DROGON_FOUND_SQLite3)
# 'OR DROGON_FOUND_DUCKDB' add by dq
if (pg_FOUND OR DROGON_FOUND_MYSQL OR DROGON_FOUND_SQLite3 OR DROGON_FOUND_DUCKDB)
if (pg_FOUND)
option(USE_POSTGRESQL "Enable PostgreSQL" ON)
else (pg_FOUND)
Expand All @@ -640,7 +680,15 @@ if (pg_FOUND OR DROGON_FOUND_MYSQL OR DROGON_FOUND_SQLite3)
else (DROGON_FOUND_SQLite3)
option(USE_SQLITE3 "Disable Sqlite3" OFF)
endif (DROGON_FOUND_SQLite3)
endif (pg_FOUND OR DROGON_FOUND_MYSQL OR DROGON_FOUND_SQLite3)
# add by dq
if (DROGON_FOUND_DUCKDB)
message(STATUS "DuckDB was found.")
option(USE_DUCKDB "Enable DuckDB" ON)
else (DROGON_FOUND_DUCKDB)
message(STATUS "DuckDB was not found.")
option(USE_DUCKDB "Disable DuckDB" OFF)
endif (DROGON_FOUND_DUCKDB)
endif (pg_FOUND OR DROGON_FOUND_MYSQL OR DROGON_FOUND_SQLite3 OR DROGON_FOUND_DUCKDB)

get_filename_component(COMPILER_COMMAND ${CMAKE_CXX_COMPILER} NAME)
set(COMPILER_ID ${CMAKE_CXX_COMPILER_ID})
Expand Down Expand Up @@ -684,6 +732,10 @@ if (BUILD_TESTING)
if (DROGON_FOUND_SQLite3)
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/sqlite3_impl/test)
endif (DROGON_FOUND_SQLite3)
# Add DuckDB test
if (DROGON_FOUND_DUCKDB)
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/duckdb_impl/test)
endif (DROGON_FOUND_DUCKDB)
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/tests)
endif (BUILD_TESTING)

Expand Down
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file.
### Changed

- Add toString method to all models
- Vendored in UniGIS: preflight DuckDB open/connect before starting the internal worker loop and restore a valid connection loop after initialization, fixing downstream transaction-path crashes.
- Vendored in UniGIS: avoid retaining closing SQLite3/DuckDB connection objects inside delayed reconnect callbacks, preventing self-thread `EventLoopThread` destruction and heap corruption on open failure.

## [1.9.11] - 2025-06-20

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ English | [简体中文](./README.zh-CN.md) | [繁體中文](./README.zh-TW.md)
### Overview
**Drogon** is a C++17/20 based HTTP application framework. Drogon can be used to easily build various types of web application server programs using C++. **Drogon** is the name of a dragon from the American TV series *Game of Thrones*, which I really enjoy.

## Vendored changes in this repository

This repository carries a small set of downstream patches on top of upstream Drogon for UniGIS Map Service:

- DuckDB connections perform a preflight open/connect before starting the internal worker loop.
- DuckDB connections restore a valid exposed loop after successful initialization so transaction paths can safely queue work.
- SQLite3 and DuckDB reconnect timers avoid retaining closing connection objects, preventing self-thread `EventLoopThread` destruction and related heap corruption during connection-open failures.

These notes only document the local vendored behavior in this repository. Upstream Drogon remains the source of truth for general framework documentation.

Drogon is a cross-platform framework, It supports Linux, macOS, FreeBSD, OpenBSD, HaikuOS, and Windows. Its main features are as follows:

* Use a non-blocking I/O network lib based on epoll (kqueue under macOS/FreeBSD) to provide high-concurrency, high-performance network IO, please visit the [TFB Tests Results](https://www.techempower.com/benchmarks/#section=data-r19&hw=ph&test=composite) for more details;
Expand Down
12 changes: 11 additions & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
**Drogon**是一个基于C++17/20的Http应用框架,使用Drogon可以方便的使用C++构建各种类型的Web应用服务端程序。
本版本库是github上[Drogon工程](https://github.com/an-tao/drogon)的镜像库。**Drogon**是作者非常喜欢的美剧《权力的游戏》中的一条龙的名字(汉译作卓耿),和龙有关但并不是dragon的误写,为了不至于引起不必要的误会这里说明一下。

## 本仓库的本地补丁说明

本仓库 vendored 的 Drogon 在上游基础上带有少量的本地补丁:

- DuckDB 连接会在启动内部 worker loop 之前先做数据库预打开与连接预检。
- DuckDB 连接初始化成功后会恢复有效的对外 `loop_`,保证事务路径可以安全投递任务。
- SQLite3 与 DuckDB 的重连定时器不再延迟持有正在关闭的连接对象,避免连接打开失败时出现自线程 `EventLoopThread` 析构与后续堆损坏。

这里的说明仅用于记录本仓库的 vendored 行为,Drogon 的通用使用方式和正式文档仍以上游工程为准。

Drogon是一个跨平台框架,它支持Linux,也支持macOS、FreeBSD,OpenBSD,HaikuOS,和Windows。它的主要特点如下:

* 网络层使用基于epoll(macOS/FreeBSD下是kqueue)的非阻塞IO框架,提供高并发、高性能的网络IO。详细请见[TFB Tests Results](https://www.techempower.com/benchmarks/#section=data-r19&hw=ph&test=composite);
Expand Down Expand Up @@ -202,4 +212,4 @@ class User : public drogon::HttpController<User>

![](https://github.com/an-tao/drogon/wiki/images/qrcode_wechat.jpg)

会不定期推送一些Drogon的使用技巧和更新信息,欢迎关注。
会不定期推送一些Drogon的使用技巧和更新信息,欢迎关注。
3 changes: 3 additions & 0 deletions cmake/templates/DrogonConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ endif()
if(@SQLite3_FOUND@)
find_dependency(SQLite3)
endif()
if(@DUCKDB_FOUND@)
find_dependency(Duckdb)
endif()
if(@MySQL_FOUND@)
find_dependency(MySQL)
endif()
Expand Down
1 change: 1 addition & 0 deletions cmake/templates/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#cmakedefine01 LIBPQ_SUPPORTS_BATCH_MODE
#cmakedefine01 USE_MYSQL
#cmakedefine01 USE_SQLITE3
#cmakedefine01 USE_DUCKDB
#cmakedefine01 HAS_STD_FILESYSTEM_PATH
#cmakedefine OpenSSL_FOUND
#cmakedefine Boost_FOUND
Expand Down
6 changes: 6 additions & 0 deletions cmake/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.5)
project(UUIDTests CXX)

# This CMakeLists.txt is used by try_compile to test UUID library variants
add_executable(normal_uuid_lib_test normal_uuid_lib_test.cc)
add_executable(ossp_uuid_lib_test ossp_uuid_lib_test.cc)
10 changes: 5 additions & 5 deletions drogon_ctl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ foreach(cspFile ${SCP_LIST})
get_filename_component(classname ${cspFile} NAME_WE)
message(STATUS "view classname:" ${classname})
add_custom_command(OUTPUT ${classname}.h ${classname}.cc
COMMAND ${DROGON_CTL}
ARGS
create
view
${cspFile}
COMMAND $<TARGET_FILE:_drogon_ctl>
ARGS
create
view
${cspFile}
DEPENDS ${cspFile}
VERBATIM)
set(TEMPL_SRC ${TEMPL_SRC} ${classname}.cc)
Expand Down
Loading