Skip to content

Commit 3f8c555

Browse files
Added support for MySQL (#33); resolves #18
1 parent 1424d29 commit 3f8c555

File tree

81 files changed

+4338
-23
lines changed

Some content is hidden

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

81 files changed

+4338
-23
lines changed

.github/workflows/linux-cxx20-conan.yaml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,37 @@ jobs:
1010
include:
1111
- compiler: llvm
1212
compiler-version: 16
13+
link: "static"
1314
- compiler: llvm
1415
compiler-version: 18
16+
link: "static"
1517
- compiler: gcc
1618
compiler-version: 11
1719
additional-dep: "g++-11"
20+
link: "static"
1821
- compiler: gcc
1922
compiler-version: 12
23+
link: "static"
2024
- compiler: gcc
2125
compiler-version: 14
22-
name: "${{ github.job }} (${{ matrix.compiler }}-${{ matrix.compiler-version }})"
26+
link: "static"
27+
- compiler: llvm
28+
compiler-version: 16
29+
link: "shared"
30+
- compiler: llvm
31+
compiler-version: 18
32+
link: "shared"
33+
- compiler: gcc
34+
compiler-version: 11
35+
additional-dep: "g++-11"
36+
link: "shared"
37+
- compiler: gcc
38+
compiler-version: 12
39+
link: "shared"
40+
- compiler: gcc
41+
compiler-version: 14
42+
link: "shared"
43+
name: "${{ github.job }} (${{ matrix.compiler }}-${{ matrix.compiler-version }}-${{ matrix.link }})"
2344
runs-on: ubuntu-latest
2445
steps:
2546
- name: Checkout
@@ -47,4 +68,8 @@ jobs:
4768
sudo ln -s $(which ccache) /usr/local/bin/$CC
4869
sudo ln -s $(which ccache) /usr/local/bin/$CXX
4970
$CXX --version
50-
conan build . --build=missing -s compiler.cppstd=gnu20
71+
if [[ "${{ matrix.link }}" == "static" ]]; then
72+
conan build . --build=missing -s compiler.cppstd=gnu20
73+
else
74+
conan build . --build=missing -s compiler.cppstd=gnu20 -o sqlgen/*:with_mysql=True -o */*:shared=True
75+
fi

.github/workflows/linux-cxx20-vcpkg.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ jobs:
4343
- compiler: gcc
4444
compiler-version: 14
4545
db: sqlite
46+
- compiler: llvm
47+
compiler-version: 16
48+
db: mysql
49+
- compiler: llvm
50+
compiler-version: 18
51+
db: mysql
52+
- compiler: gcc
53+
compiler-version: 11
54+
additional-dep: "g++-11"
55+
db: mysql
56+
- compiler: gcc
57+
compiler-version: 12
58+
db: mysql
59+
- compiler: gcc
60+
compiler-version: 14
61+
db: mysql
4662
name: "${{ github.job }} (${{ matrix.compiler }}-${{ matrix.compiler-version }}-${{ matrix.db }})"
4763
runs-on: ubuntu-latest
4864
steps:
@@ -98,11 +114,33 @@ jobs:
98114
$CXX --version
99115
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_POSTGRES=OFF
100116
cmake --build build
117+
- name: Compile
118+
if: matrix.db == 'mysql'
119+
run: |
120+
if [[ "${{ matrix.compiler }}" == "llvm" ]]; then
121+
export CC=clang-${{ matrix.compiler-version }}
122+
export CXX=clang++-${{ matrix.compiler-version }}
123+
elif [[ "${{ matrix.compiler }}" == "gcc" ]]; then
124+
export CC=gcc-${{ matrix.compiler-version }}
125+
export CXX=g++-${{ matrix.compiler-version }}
126+
fi
127+
sudo ln -s $(which ccache) /usr/local/bin/$CC
128+
sudo ln -s $(which ccache) /usr/local/bin/$CXX
129+
$CXX --version
130+
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_MYSQL=ON -DSQLGEN_POSTGRES=OFF -DSQLGEN_SQLITE3=OFF -DBUILD_SHARED_LIBS=ON -DVCPKG_TARGET_TRIPLET=x64-linux-dynamic
131+
cmake --build build
101132
- name: Set up postgres
102133
if: matrix.db == 'postgres'
103134
run: |
104135
sudo systemctl start postgresql.service
105136
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'password';"
137+
- name: Set up mysql
138+
if: matrix.db == 'mysql'
139+
run: |
140+
sudo systemctl start mysql
141+
sudo mysql -uroot -proot -e "CREATE USER sqlgen IDENTIFIED WITH mysql_native_password BY 'password';"
142+
sudo mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON *.* TO 'sqlgen';"
143+
sudo mysql -uroot -proot -e "SET GLOBAL time_zone = '+0:00';"
106144
- name: Run tests
107145
run: |
108146
ctest --test-dir build --output-on-failure

.github/workflows/macos-cxx20-conan.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ jobs:
99
matrix:
1010
include:
1111
- os: "macos-latest"
12+
link: "static"
1213
- os: "macos-13"
13-
name: "${{ github.job }} (${{ matrix.os }})"
14+
link: "static"
15+
- os: "macos-latest"
16+
link: "shared"
17+
- os: "macos-13"
18+
link: "shared"
19+
name: "${{ github.job }} (${{ matrix.os }}-${{ matrix.link }})"
1420
runs-on: ${{ matrix.os }}
1521
steps:
1622
- name: Checkout
@@ -30,4 +36,8 @@ jobs:
3036
CXX: clang++
3137
run: |
3238
$CXX --version
33-
conan build . --build=missing -s compiler.cppstd=gnu20
39+
if [[ "${{ matrix.link }}" == "static" ]]; then
40+
conan build . --build=missing -s compiler.cppstd=gnu20
41+
else
42+
conan build . --build=missing -s compiler.cppstd=gnu20 -o sqlgen/*:with_mysql=True -o */*:shared=True
43+
fi

.github/workflows/macos-cxx20-vcpkg.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ jobs:
1515
db: postgres
1616
- os: "macos-latest"
1717
db: sqlite
18+
- os: "macos-latest"
19+
db: mysql
1820
- os: "macos-13"
1921
db: postgres
2022
- os: "macos-13"
2123
db: sqlite
24+
- os: "macos-13"
25+
db: mysql
2226
name: "${{ github.job }} (${{ matrix.os }}-${{ matrix.db }})"
2327
runs-on: ${{ matrix.os }}
2428
steps:
@@ -70,6 +74,23 @@ jobs:
7074
$CXX --version
7175
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_POSTGRES=OFF
7276
cmake --build build -j 4
77+
- name: Compile
78+
if: matrix.db == 'mysql'
79+
env:
80+
CC: clang
81+
CXX: clang++
82+
run: |
83+
if [[ "${{ matrix.os == 'macos-latest' }}" == "true" ]]; then
84+
export VCPKG_FORCE_SYSTEM_BINARIES=arm
85+
export CMAKE_GENERATOR=Ninja
86+
fi
87+
$CXX --version
88+
if [[ "${{ matrix.os == 'macos-latest' }}" == "true" ]]; then
89+
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_MYSQL=ON -DSQLGEN_POSTGRES=OFF -DSQLGEN_SQLITE3=OFF -DBUILD_SHARED_LIBS=ON -DVCPKG_TARGET_TRIPLET=arm64-osx-dynamic -DSQLGEN_BUILD_DRY_TESTS_ONLY=ON
90+
else
91+
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_MYSQL=ON -DSQLGEN_POSTGRES=OFF -DSQLGEN_SQLITE3=OFF -DBUILD_SHARED_LIBS=ON -DVCPKG_TARGET_TRIPLET=x64-osx-dynamic -DSQLGEN_BUILD_DRY_TESTS_ONLY=ON
92+
fi
93+
cmake --build build -j 4
7394
- name: Run tests
7495
run: |
7596
ctest --test-dir build --output-on-failure

.github/workflows/windows-cxx20-vcpkg.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
include:
1414
- db: postgres
1515
- db: sqlite
16+
- db: mysql
1617
name: "(windows-${{ matrix.db }})"
1718
runs-on: windows-latest
1819
steps:
@@ -39,6 +40,11 @@ jobs:
3940
run: |
4041
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_POSTGRES=OFF
4142
cmake --build build --config Release -j4
43+
- name: Compile
44+
if: matrix.db == 'mysql'
45+
run: |
46+
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_MYSQL=ON -DSQLGEN_POSTGRES=OFF -DSQLGEN_SQLITE3=OFF -DSQLGEN_BUILD_DRY_TESTS_ONLY=ON
47+
cmake --build build --config Release -j4
4248
- name: Run tests
4349
run: |
4450
ctest --test-dir build --output-on-failure

CMakeLists.txt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.23)
22

33
option(SQLGEN_BUILD_SHARED "Build shared library" ${BUILD_SHARED_LIBS})
44

5+
option(SQLGEN_MYSQL "Enable MySQL support" OFF)
6+
57
option(SQLGEN_POSTGRES "Enable PostgreSQL support" ON) # enabled by default
68

79
option(SQLGEN_SQLITE3 "Enable SQLite3 support" ON) # enabled by default
@@ -15,6 +17,7 @@ if (NOT DEFINED CMAKE_CXX_STANDARD)
1517
set(CMAKE_CXX_STANDARD 20)
1618
endif()
1719

20+
1821
set(SQLGEN_USE_VCPKG_DEFAULT ON)
1922

2023
option(SQLGEN_USE_VCPKG "Use VCPKG to download and build dependencies" ${SQLGEN_USE_VCPKG_DEFAULT})
@@ -24,18 +27,22 @@ if (SQLGEN_USE_VCPKG)
2427
list(APPEND VCPKG_MANIFEST_FEATURES "tests")
2528
endif()
2629

30+
if (SQLGEN_MYSQL)
31+
list(APPEND VCPKG_MANIFEST_FEATURES "mysql")
32+
endif()
33+
2734
if (SQLGEN_POSTGRES)
2835
list(APPEND VCPKG_MANIFEST_FEATURES "postgres")
2936
endif()
3037

3138
if (SQLGEN_SQLITE3)
3239
list(APPEND VCPKG_MANIFEST_FEATURES "sqlite3")
3340
endif()
34-
41+
3542
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file")
3643
endif ()
3744

38-
project(sqlgen VERSION 0.0.1 LANGUAGES CXX)
45+
project(sqlgen VERSION 0.1.0 LANGUAGES CXX)
3946

4047
if (SQLGEN_BUILD_SHARED)
4148
add_library(sqlgen SHARED)
@@ -59,6 +66,21 @@ target_include_directories(
5966
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
6067
$<INSTALL_INTERFACE:include>)
6168

69+
if(SQLGEN_MYSQL)
70+
list(APPEND SQLGEN_SOURCES src/sqlgen_mysql.cpp)
71+
if (SQLGEN_USE_VCPKG)
72+
if (NOT TARGET unofficial-libmariadb)
73+
find_package(unofficial-libmariadb CONFIG REQUIRED)
74+
endif()
75+
target_link_libraries(sqlgen PUBLIC unofficial::libmariadb)
76+
else()
77+
if (NOT TARGET mariadb-connector-c)
78+
find_package(mariadb-connector-c REQUIRED)
79+
endif()
80+
target_link_libraries(sqlgen PUBLIC mariadb-connector-c::mariadb-connector-c)
81+
endif()
82+
endif()
83+
6284
if (SQLGEN_POSTGRES)
6385
list(APPEND SQLGEN_SOURCES src/sqlgen_postgres.cpp)
6486
if (NOT TARGET PostgreSQL)

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ Together, reflect-cpp and sqlgen enable reliable and efficient ETL pipelines.
2323
- 🔌 **Multiple Backends**: Support for PostgreSQL and SQLite
2424
- 🔍 **Reflection Integration**: Seamless integration with [reflect-cpp](https://github.com/getml/reflect-cpp)
2525

26+
## Supported databases
27+
28+
The following table lists the databases currently supported by sqlgen and the underlying libraries used:
29+
30+
| Database | Library | Version | License | Remarks |
31+
|---------------|--------------------------------------------------------------------------|--------------|---------------| -----------------------------------------------------|
32+
| MySQL/MariaDB | [libmariadb](https://github.com/mariadb-corporation/mariadb-connector-c) | >= 3.4.5 | LGPL | |
33+
| PostgreSQL | [libpq](https://github.com/postgres/postgres) | >= 16.4 | PostgreSQL | Will work for all libpq-compatible databases |
34+
| sqlite | [sqlite](https://sqlite.org/index.html) | >= 3.49.1 | Public Domain | |
35+
2636
## Quick Start
2737

2838
### Installation using vcpkg
@@ -47,6 +57,14 @@ cmake --build build -j 4 # gcc, clang
4757
cmake --build build --config Release -j 4 # MSVC
4858
```
4959

60+
This will build the static library. To build the shared library
61+
add `-DBUILD_SHARED_LIBS=ON -DVCPKG_TARGET_TRIPLET=...` to the first line.
62+
Run `./vcpkg/vcpkg help triplets` to view all supported triplets.
63+
Common triplets for shared libraries are `x64-linux-dynamic`,
64+
`arm64-osx-dynamic` or `x64-osx-dynamic`.
65+
66+
Add `-DSQLGEN_BUILD_MYSQL=ON` to support MySQL/MariaDB.
67+
5068
4. Include in your CMake project:
5169
```cmake
5270
find_package(sqlgen REQUIRED)
@@ -70,6 +88,17 @@ For older versions of pip, you can also use `pip` instead of `pipx`.
7088
conan build . --build=missing -s compiler.cppstd=gnu20
7189
```
7290

91+
This will build the static library. To build the shared library,
92+
add `-o */*:shared=True`.
93+
94+
Add `-o sqlgen/*:with_mysql=True` to support MySQL/MariaDB.
95+
96+
3. Include in your CMake project:
97+
```cmake
98+
find_package(sqlgen REQUIRED)
99+
target_link_libraries(your_target PRIVATE sqlgen::sqlgen)
100+
```
101+
73102
You can call `conan inspect .` to get an overview of the supported options.
74103

75104
## Usage Examples

conanfile.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ class SQLGenConan(ConanFile):
2626
options = {
2727
"shared": [True, False],
2828
"fPIC": [True, False],
29+
"with_mysql": [True, False],
2930
"with_postgres": [True, False],
3031
"with_sqlite3": [True, False],
3132
}
3233
default_options = {
3334
"shared": False,
3435
"fPIC": True,
36+
"with_mysql": False,
3537
"with_postgres": True,
3638
"with_sqlite3": True,
3739
}
@@ -46,6 +48,8 @@ def configure(self):
4648

4749
def requirements(self):
4850
self.requires("reflect-cpp/0.19.0", transitive_headers=True)
51+
if self.options.with_mysql:
52+
self.requires("mariadb-connector-c/3.4.3", transitive_headers=True)
4953
if self.options.with_postgres:
5054
self.requires("libpq/17.5", transitive_headers=True)
5155
if self.options.with_sqlite3:
@@ -71,6 +75,7 @@ def generate(self):
7175
deps.generate()
7276
tc = CMakeToolchain(self)
7377
tc.cache_variables["SQLGEN_BUILD_SHARED"] = self.options.shared
78+
tc.cache_variables["SQLGEN_MYSQL"] = self.options.with_mysql
7479
tc.cache_variables["SQLGEN_POSTGRES"] = self.options.with_postgres
7580
tc.cache_variables["SQLGEN_SQLITE3"] = self.options.with_sqlite3
7681
tc.cache_variables["SQLGEN_USE_VCPKG"] = False

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Welcome to the sqlgen documentation. This guide provides detailed information ab
5050

5151
## Supported Databases
5252

53+
- [MySQL](mysql.md) - How to interact with MariaDB and MySQL
5354
- [PostgreSQL](postgres.md) - How to interact with PostgreSQL and compatible databases (Redshift, Aurora, Greenplum, CockroachDB, ...)
5455
- [SQLite](sqlite.md) - How to interact with SQLite3
5556

0 commit comments

Comments
 (0)