Skip to content

Commit dbe16fb

Browse files
committed
Merge branch 'dev'
2 parents 69f66ed + cab2555 commit dbe16fb

41 files changed

Lines changed: 958 additions & 2573 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ hello_server
4343
*.bak
4444
db.sql
4545
revoir.md
46-
main.cpp
4746
.vix-scripts
4847

4948

CMakeLists.txt

Lines changed: 36 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
# @file CMakeLists.cpp
1+
# @file CMakeLists.txt
22
# @author Gaspard Kirira
33
#
44
# Copyright 2025, Gaspard Kirira. All rights reserved.
55
# https://github.com/vixcpp/vix
66
# Use of this source code is governed by a MIT license
77
# that can be found in the License file.
88
#
9-
# Vix.cpp | ORM module
9+
# Vix.cpp | ORM module (sugar layer on top of vix::db)
1010
cmake_minimum_required(VERSION 3.20)
1111

12-
project(vix_orm VERSION 1.2.1 LANGUAGES CXX)
12+
project(vix_orm VERSION 1.3.0 LANGUAGES CXX)
1313

1414
include(GNUInstallDirs)
1515

16-
# options
16+
# ------------------------------------------------------------------------------
17+
# Options
18+
# ------------------------------------------------------------------------------
1719
option(VIX_ORM_BUILD_TESTS "Build unit tests for Vix ORM" OFF)
18-
option(VIX_ORM_BUILD_EXAMPLES "Build examples for Vix ORM" ON)
19-
20-
option(VIX_ORM_USE_MYSQL "Enable MySQL Connector/C++ driver" ON)
21-
option(VIX_ORM_REQUIRE_MYSQL "Fail if MySQL requested but not found" OFF)
22-
23-
option(VIX_ORM_USE_SQLITE "Enable SQLite3 driver" OFF)
24-
option(VIX_ORM_BUILD_TOOLS "Build ORM CLI tools (migrator)" ON)
20+
option(VIX_ORM_BUILD_EXAMPLES "Build examples for Vix ORM" OFF)
2521

2622
# language / PIC
2723
set(CMAKE_CXX_STANDARD 20)
@@ -38,166 +34,53 @@ set(_WARNINGS_MSVC /W4 /permissive-)
3834
# optional deps
3935
find_package(spdlog QUIET CONFIG)
4036

41-
# MySQL detection
42-
set(VIX_ORM_HAS_MYSQL OFF)
43-
set(MYSQLCPPCONN_LIB "")
44-
set(MYSQLCPPCONN_INCLUDE_DIR "")
45-
46-
if (VIX_ORM_USE_MYSQL)
47-
if (EXISTS "/usr/lib/x86_64-linux-gnu/libmysqlcppconn.so")
48-
set(MYSQLCPPCONN_LIB "/usr/lib/x86_64-linux-gnu/libmysqlcppconn.so")
49-
elseif (EXISTS "/usr/lib/x86_64-linux-gnu/libmysqlcppconn.so.7")
50-
set(MYSQLCPPCONN_LIB "/usr/lib/x86_64-linux-gnu/libmysqlcppconn.so.7")
51-
endif()
52-
53-
if (EXISTS "/usr/include/cppconn/connection.h")
54-
set(MYSQLCPPCONN_INCLUDE_DIR "/usr/include")
55-
endif()
56-
57-
if (NOT MYSQLCPPCONN_LIB)
58-
find_library(MYSQLCPPCONN_LIB
59-
NAMES mysqlcppconn mysqlcppconn8
60-
PATHS /usr/lib/x86_64-linux-gnu /usr/local/lib /usr/lib
61-
)
62-
endif()
63-
64-
if (NOT MYSQLCPPCONN_INCLUDE_DIR)
65-
find_path(MYSQLCPPCONN_INCLUDE_DIR
66-
NAMES cppconn/connection.h
67-
PATHS /usr/include /usr/local/include
68-
)
69-
endif()
70-
71-
if (MYSQLCPPCONN_LIB AND MYSQLCPPCONN_INCLUDE_DIR)
72-
set(VIX_ORM_HAS_MYSQL ON)
73-
message(STATUS "[vix_orm] mysql: enabled")
74-
message(STATUS " lib: ${MYSQLCPPCONN_LIB}")
75-
message(STATUS " inc: ${MYSQLCPPCONN_INCLUDE_DIR}")
76-
else()
77-
if (VIX_ORM_REQUIRE_MYSQL)
78-
message(FATAL_ERROR "[vix_orm] mysql requested but Connector/C++ not found (VIX_ORM_REQUIRE_MYSQL=ON).")
79-
endif()
80-
message(STATUS "[vix_orm] mysql: disabled (connector not found)")
81-
set(VIX_ORM_USE_MYSQL OFF)
82-
endif()
83-
endif()
84-
85-
# SQLite detection (soft)
86-
set(VIX_ORM_HAS_SQLITE OFF)
87-
set(_VIX_SQLITE_TARGET "")
88-
89-
if (VIX_ORM_USE_SQLITE)
90-
find_package(SQLite3 QUIET)
91-
92-
if (TARGET SQLite::SQLite3)
93-
set(_VIX_SQLITE_TARGET SQLite::SQLite3)
94-
elseif (TARGET SQLite3::SQLite3)
95-
add_library(SQLite::SQLite3 ALIAS SQLite3::SQLite3)
96-
set(_VIX_SQLITE_TARGET SQLite::SQLite3)
97-
endif()
98-
99-
if (SQLite3_FOUND OR _VIX_SQLITE_TARGET)
100-
set(VIX_ORM_HAS_SQLITE ON)
101-
message(STATUS "[vix_orm] sqlite: enabled")
102-
else()
103-
message(WARNING "[vix_orm] sqlite requested but not found; disabled.")
104-
set(VIX_ORM_USE_SQLITE OFF)
105-
endif()
106-
endif()
107-
108-
# sources / headers
37+
# ------------------------------------------------------------------------------
38+
# Sources / Headers (ORM sugar only)
39+
# ------------------------------------------------------------------------------
10940
set(VIX_ORM_PUBLIC_HEADERS
110-
include/vix/orm/Errors.hpp
111-
include/vix/orm/Drivers.hpp
112-
include/vix/orm/ConnectionPool.hpp
113-
include/vix/orm/Transaction.hpp
114-
include/vix/orm/QueryBuilder.hpp
11541
include/vix/orm/Entity.hpp
11642
include/vix/orm/Mapper.hpp
11743
include/vix/orm/Repository.hpp
44+
include/vix/orm/QueryBuilder.hpp
11845
include/vix/orm/UnitOfWork.hpp
119-
include/vix/orm/Migration.hpp
120-
include/vix/orm/MigrationsRunner.hpp
121-
include/vix/orm/Database.hpp
12246
include/vix/orm/orm.hpp
123-
include/vix/orm/FileMigrationsRunner.hpp
124-
include/vix/orm/Sha256.hpp
47+
include/vix/orm/db_compat.hpp
12548
)
12649

12750
set(VIX_ORM_SOURCES
128-
src/ConnectionPool.cpp
129-
src/Mapper.cpp
130-
src/MigrationsRunner.cpp
13151
src/QueryBuilder.cpp
132-
src/Repository.cpp
133-
src/Transaction.cpp
134-
src/Database.cpp
135-
src/FileMigrationsRunner.cpp
136-
src/Sha256.cpp
13752
)
13853

139-
if (VIX_ORM_HAS_MYSQL)
140-
list(APPEND VIX_ORM_PUBLIC_HEADERS include/vix/orm/MySQLDriver.hpp)
141-
list(APPEND VIX_ORM_SOURCES src/MySQLDriver.cpp)
142-
endif()
143-
144-
if (VIX_ORM_HAS_SQLITE)
145-
list(APPEND VIX_ORM_PUBLIC_HEADERS include/vix/orm/SqliteDriver.hpp)
146-
list(APPEND VIX_ORM_SOURCES src/SqliteDriver.cpp)
147-
endif()
148-
149-
# If building ORM standalone (not from umbrella), bring core as subdir
54+
# ------------------------------------------------------------------------------
55+
# Bring required modules when building standalone
56+
# ------------------------------------------------------------------------------
15057
if (NOT TARGET vix::core)
15158
add_subdirectory(../core core_build)
15259
endif()
15360

154-
# library target
155-
add_library(vix_orm STATIC ${VIX_ORM_SOURCES} ${VIX_ORM_PUBLIC_HEADERS})
156-
add_library(vix::orm ALIAS vix_orm)
157-
158-
# tools (migrator) NOT an example
159-
if (VIX_ORM_BUILD_TOOLS)
160-
add_executable(vix_orm_migrator)
161-
162-
target_sources(vix_orm_migrator PRIVATE
163-
${CMAKE_CURRENT_SOURCE_DIR}/tools/migrator/main.cpp
164-
${CMAKE_CURRENT_SOURCE_DIR}/tools/migrator/MigratorCLI.cpp
165-
)
166-
167-
target_link_libraries(vix_orm_migrator PRIVATE vix::orm)
168-
target_compile_features(vix_orm_migrator PRIVATE cxx_std_20)
169-
170-
if (MSVC)
171-
target_compile_options(vix_orm_migrator PRIVATE ${_WARNINGS_MSVC})
172-
else()
173-
target_compile_options(vix_orm_migrator PRIVATE ${_WARNINGS_GNU})
174-
endif()
175-
176-
install(TARGETS vix_orm_migrator
177-
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/vix
178-
)
61+
if (NOT TARGET vix::db)
62+
add_subdirectory(../db db_build)
17963
endif()
18064

65+
# ------------------------------------------------------------------------------
66+
# Library target
67+
# ------------------------------------------------------------------------------
68+
add_library(vix_orm STATIC ${VIX_ORM_SOURCES} ${VIX_ORM_PUBLIC_HEADERS})
69+
add_library(vix::orm ALIAS vix_orm)
18170

182-
# Keep feature macros consistent everywhere (build + consumers)
183-
target_compile_definitions(vix_orm PUBLIC
184-
VIX_ORM_HAS_MYSQL=$<BOOL:${VIX_ORM_HAS_MYSQL}>
185-
VIX_ORM_HAS_SQLITE=$<BOOL:${VIX_ORM_HAS_SQLITE}>
186-
)
187-
188-
# export name => installed imported target is vix::orm
18971
set_target_properties(vix_orm PROPERTIES EXPORT_NAME orm)
19072

19173
target_include_directories(vix_orm PUBLIC
19274
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
19375
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
19476
)
195-
# ORM depends on Vix Core (Config.hpp, http, json, etc.)
196-
target_link_libraries(vix_orm PUBLIC vix::core)
197-
# Inherit umbrella sanitizers if present
77+
78+
target_link_libraries(vix_orm PUBLIC vix::core vix::db)
79+
19880
if (VIX_ENABLE_SANITIZERS AND TARGET vix_sanitizers)
19981
target_link_libraries(vix_orm PUBLIC vix_sanitizers)
20082
endif()
83+
20184
if (MSVC)
20285
target_compile_options(vix_orm PRIVATE ${_WARNINGS_MSVC})
20386
else()
@@ -206,7 +89,6 @@ endif()
20689

20790
# deps / defines
20891
if (spdlog_FOUND)
209-
# accept either target name
21092
if (TARGET spdlog::spdlog_header_only)
21193
target_link_libraries(vix_orm PUBLIC spdlog::spdlog_header_only)
21294
elseif (TARGET spdlog::spdlog)
@@ -217,28 +99,15 @@ else()
21799
target_compile_definitions(vix_orm PUBLIC VIX_ORM_NO_LOGGER=1)
218100
endif()
219101

220-
# MySQL linkage (THIS FIXES YOUR LINK ERROR)
221-
if (VIX_ORM_HAS_MYSQL)
222-
target_include_directories(vix_orm PUBLIC "${MYSQLCPPCONN_INCLUDE_DIR}")
223-
target_link_libraries(vix_orm PUBLIC "${MYSQLCPPCONN_LIB}")
224-
endif()
225-
226-
# SQLite linkage
227-
if (VIX_ORM_HAS_SQLITE)
228-
if (_VIX_SQLITE_TARGET)
229-
target_link_libraries(vix_orm PUBLIC ${_VIX_SQLITE_TARGET})
230-
else()
231-
message(WARNING "[vix_orm] sqlite enabled but no target found; linkage skipped.")
232-
endif()
233-
endif()
234-
235-
# examples
102+
# ------------------------------------------------------------------------------
103+
# Examples
104+
# ------------------------------------------------------------------------------
236105
function(vix_add_orm_example name file)
237106
add_executable(${name} ${file})
238107
target_link_libraries(${name} PRIVATE vix::orm)
239108

240109
if (VIX_ENABLE_SANITIZERS AND TARGET vix_sanitizers)
241-
target_link_libraries(${name} PRIVATE vix_sanitizers)
110+
target_link_libraries(${name} PRIVATE vix_sanitizers)
242111
endif()
243112

244113
if (MSVC)
@@ -249,23 +118,19 @@ function(vix_add_orm_example name file)
249118
endfunction()
250119

251120
if (VIX_ORM_BUILD_EXAMPLES)
252-
253-
vix_add_orm_example(batch_insert_tx
254-
${CMAKE_CURRENT_SOURCE_DIR}/examples/batch_insert_tx.cpp)
255-
vix_add_orm_example(vix_orm_users
256-
${CMAKE_CURRENT_SOURCE_DIR}/examples/users_crud.cpp)
257-
vix_add_orm_example(querybuilder_update
258-
${CMAKE_CURRENT_SOURCE_DIR}/examples/querybuilder_update.cpp)
259121
vix_add_orm_example(repository_crud_full
260122
${CMAKE_CURRENT_SOURCE_DIR}/examples/repository_crud_full.cpp)
123+
vix_add_orm_example(querybuilder_update
124+
${CMAKE_CURRENT_SOURCE_DIR}/examples/querybuilder_update.cpp)
261125
vix_add_orm_example(tx_unit_of_work
262126
${CMAKE_CURRENT_SOURCE_DIR}/examples/tx_unit_of_work.cpp)
263127
vix_add_orm_example(error_handling
264128
${CMAKE_CURRENT_SOURCE_DIR}/examples/error_handling.cpp)
265-
266129
endif()
267130

268-
# install / export via umbrella export-set "VixTargets"
131+
# ------------------------------------------------------------------------------
132+
# Install / export via umbrella export-set "VixTargets"
133+
# ------------------------------------------------------------------------------
269134
if (DEFINED VIX_UMBRELLA_BUILD)
270135
install(TARGETS vix_orm
271136
EXPORT VixTargets
@@ -290,6 +155,5 @@ install(DIRECTORY include/
290155

291156
message(STATUS "------------------------------------------------------")
292157
message(STATUS "[vix_orm] configured (${PROJECT_VERSION})")
293-
message(STATUS "[vix_orm] mysql: requested=${VIX_ORM_USE_MYSQL} available=${VIX_ORM_HAS_MYSQL}")
294-
message(STATUS "[vix_orm] sqlite: requested=${VIX_ORM_USE_SQLITE} available=${VIX_ORM_HAS_SQLITE}")
158+
message(STATUS "[vix_orm] depends on: vix::db (drivers) + vix::core (base)")
295159
message(STATUS "------------------------------------------------------")

0 commit comments

Comments
 (0)