Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
435b029
Generate .lib files when building shared on Windows
liuzicheng1987 Nov 2, 2025
383f75e
Build shared libs
liuzicheng1987 Nov 2, 2025
c3105c0
Cancel in-progress builds
liuzicheng1987 Nov 2, 2025
5d83cad
Bumpef version to 0.4.0
liuzicheng1987 Nov 2, 2025
267dd01
Fixed groups
liuzicheng1987 Nov 2, 2025
cb98d08
Next attempt to fix the groups
liuzicheng1987 Nov 2, 2025
cb7e48a
Moved concurrency ins
liuzicheng1987 Nov 2, 2025
0eda53e
Move the concurrency inside
liuzicheng1987 Nov 2, 2025
e3c88bd
Next fix
liuzicheng1987 Nov 2, 2025
f283206
Add to CMakeLists.txt
liuzicheng1987 Nov 2, 2025
8b1082b
Always build shared libs on Windows in the test pipeline
liuzicheng1987 Nov 2, 2025
657d128
Move everything to the .cpp
liuzicheng1987 Nov 2, 2025
8d30800
Adapted postgres and sqlite as well
liuzicheng1987 Nov 2, 2025
70bc36e
Outsource destructors as well
liuzicheng1987 Nov 2, 2025
c6858b7
Export iterator base as well
liuzicheng1987 Nov 2, 2025
b843862
Add IteratorBase.cpp
liuzicheng1987 Nov 2, 2025
931a9f2
Started completely removing IteratorBase
liuzicheng1987 Nov 2, 2025
af32103
Adapted mysql and postgres
liuzicheng1987 Nov 2, 2025
028db6f
Fixed headers
liuzicheng1987 Nov 2, 2025
ed9b40b
SQLGEN_API to the beginning
liuzicheng1987 Nov 2, 2025
ff1c36f
Fixed typo
liuzicheng1987 Nov 2, 2025
92b19e0
Adapted tests
liuzicheng1987 Nov 2, 2025
1326365
Added CMAKE_EXPORT_COMPILE_COMMANDS
liuzicheng1987 Nov 2, 2025
65c94e7
Do not capitalize
liuzicheng1987 Nov 2, 2025
8d038bd
WINDOWS_EXPORT_ALL_SYMBOLS
liuzicheng1987 Nov 2, 2025
2a484d0
Use SQLGEN_BUILD_SHARED instead of BUILD_SHARED_LIBS
liuzicheng1987 Nov 2, 2025
189e1a4
Remove unneeded headers
liuzicheng1987 Nov 2, 2025
8696628
Reinsert compile commands
liuzicheng1987 Nov 2, 2025
3aba75c
Always use dllexport
liuzicheng1987 Nov 2, 2025
fb95417
Turn off warnings in Release mode
liuzicheng1987 Nov 2, 2025
262aa6c
Added .cache to .gitignore
liuzicheng1987 Nov 2, 2025
73a27e8
Check headers separately
liuzicheng1987 Nov 2, 2025
c3c4a50
Next attempt
liuzicheng1987 Nov 2, 2025
9d07ea0
Fixed triplet
liuzicheng1987 Nov 2, 2025
01cde60
Use proper targets for all formats
liuzicheng1987 Nov 2, 2025
cedb1e6
Added CMAKE_BUILD_TYPE=Release
liuzicheng1987 Nov 2, 2025
dd960ee
Don't build with Ninja on Windows
liuzicheng1987 Nov 2, 2025
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
4 changes: 4 additions & 0 deletions .github/workflows/linux-cxx20-conan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: linux-cxx20-conan

on: [push, pull_request]


jobs:
linux:
strategy:
Expand Down Expand Up @@ -35,6 +36,9 @@ jobs:
compiler-version: 12
link: "shared"
name: "${{ github.job }} (${{ matrix.compiler }}-${{ matrix.compiler-version }}-${{ matrix.link }})"
concurrency:
group: ci-${{ github.ref }}-${{ github.job }}-${{ matrix.compiler }}-${{ matrix.compiler-version }}-${{ matrix.link }}
cancel-in-progress: true
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/linux-cxx20-vcpkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: linux-cxx20-vcpkg

on: [push, pull_request]


env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"

Expand Down Expand Up @@ -60,6 +61,9 @@ jobs:
compiler-version: 14
db: mysql
name: "${{ github.job }} (${{ matrix.compiler }}-${{ matrix.compiler-version }}-${{ matrix.db }})"
concurrency:
group: ci-${{ github.ref }}-${{ github.job }}-${{ matrix.compiler }}-${{ matrix.compiler-version }}-${{ matrix.db }}
cancel-in-progress: true
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/macos-cxx20-conan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: macos-cxx20-conan

on: [push, pull_request]


jobs:
macos-clang:
strategy:
Expand All @@ -17,6 +18,9 @@ jobs:
- os: "macos-13"
link: "shared"
name: "${{ github.job }} (${{ matrix.os }}-${{ matrix.link }})"
concurrency:
group: ci-${{ github.ref }}-${{ github.job }}-${{ matrix.os }}-${{ matrix.link }}
cancel-in-progress: true
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/macos-cxx20-vcpkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: macos-cxx20-vcpkg

on: [push, pull_request]


env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"

Expand All @@ -24,6 +25,9 @@ jobs:
- os: "macos-13"
db: mysql
name: "${{ github.job }} (${{ matrix.os }}-${{ matrix.db }})"
concurrency:
group: ci-${{ github.ref }}-${{ github.job }}-${{ matrix.os }}-${{ matrix.db }}
cancel-in-progress: true
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand Down
16 changes: 13 additions & 3 deletions .github/workflows/windows-cxx20-vcpkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ jobs:
- db: postgres
- db: sqlite
- db: mysql
- db: headers
name: "(windows-${{ matrix.db }})"
concurrency:
group: ci-${{ github.ref }}-windows-${{ matrix.db }}
cancel-in-progress: true
runs-on: windows-latest
steps:
- name: Checkout
Expand All @@ -30,21 +34,27 @@ jobs:
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- uses: ilammy/msvc-dev-cmd@v1
- uses: lukka/run-vcpkg@v11
- name: Compile
if: matrix.db == 'headers'
run: |
cmake -S . -B build -DCMAKE_CXX_STANDARD=20 -DSQLGEN_CHECK_HEADERS=ON
cmake --build build --config Release -j4
- name: Compile
if: matrix.db == 'postgres'
run: |
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_SQLITE3=OFF -DSQLGEN_BUILD_DRY_TESTS_ONLY=ON
cmake -S . -B build -DCMAKE_CXX_STANDARD=20 -DCMAKE_BUILD_TYPE=Release -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_SQLITE3=OFF -DSQLGEN_BUILD_DRY_TESTS_ONLY=ON -DBUILD_SHARED_LIBS=ON -DVCPKG_TARGET_TRIPLET=x64-windows-release
cmake --build build --config Release -j4
- name: Compile
if: matrix.db == 'sqlite'
run: |
cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=20 -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_POSTGRES=OFF -DSQLGEN_CHECK_HEADERS=ON
cmake -S . -B build -DCMAKE_CXX_STANDARD=20 -DCMAKE_BUILD_TYPE=Release -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_POSTGRES=OFF -DBUILD_SHARED_LIBS=ON -DVCPKG_TARGET_TRIPLET=x64-windows-release
cmake --build build --config Release -j4
- name: Compile
if: matrix.db == 'mysql'
run: |
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
cmake -S . -B build -DCMAKE_CXX_STANDARD=20 -DCMAKE_BUILD_TYPE=Release -DSQLGEN_BUILD_TESTS=ON -DSQLGEN_MYSQL=ON -DSQLGEN_POSTGRES=OFF -DSQLGEN_SQLITE3=OFF -DSQLGEN_BUILD_DRY_TESTS_ONLY=ON -DBUILD_SHARED_LIBS=ON -DVCPKG_TARGET_TRIPLET=x64-windows-release
cmake --build build --config Release -j4
- name: Run tests
if: matrix.db != 'headers'
run: |
ctest --test-dir build --output-on-failure
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*.out
*.app

.cache/
build/
vcpkg_installed/
CMakeUserPresets.json
Expand Down
32 changes: 28 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.23)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

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

option(SQLGEN_MYSQL "Enable MySQL support" OFF)
Expand Down Expand Up @@ -43,7 +45,7 @@ if (SQLGEN_USE_VCPKG)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file")
endif ()

project(sqlgen VERSION 0.3.0 LANGUAGES CXX)
project(sqlgen VERSION 0.4.0 LANGUAGES CXX)

if (SQLGEN_BUILD_SHARED)
add_library(sqlgen SHARED)
Expand All @@ -52,10 +54,30 @@ else()
add_library(sqlgen STATIC)
endif()

add_library(sqlgen::sqlgen ALIAS sqlgen)

if (MSVC)
target_compile_options(sqlgen PRIVATE $<$<CONFIG:Debug>:-Wall>)
target_compile_options(sqlgen PRIVATE
$<$<CONFIG:Debug>:
-Wall
>
$<$<CONFIG:Release>:
-DNDEBUG
>
)
else()
target_compile_options(sqlgen PRIVATE $<$<CONFIG:Debug>:-Wall -Wextra>)
target_compile_options(sqlgen PRIVATE
$<$<CONFIG:Debug>:
-Wall -Wextra -Wpedantic -Wshadow -Wconversion
>
$<$<CONFIG:Release>:
-DNDEBUG
>
)
endif()

if (SQLGEN_BUILD_SHARED)
target_compile_definitions(sqlgen PUBLIC SQLGEN_BUILD_SHARED)
endif()

set(SQLGEN_SOURCES
Expand Down Expand Up @@ -114,9 +136,11 @@ set_target_properties(sqlgen PROPERTIES LINKER_LANGUAGE CXX)
target_sources(sqlgen PRIVATE ${SQLGEN_SOURCES})

if (SQLGEN_BUILD_TESTS)
add_library(sqlgen_tests_crt INTERFACE)
target_link_libraries(sqlgen_tests_crt INTERFACE sqlgen GTest::gtest_main)

enable_testing()
find_package(GTest CONFIG REQUIRED)
set(SQLGEN_GTEST_LIB sqlgen GTest::gtest_main)
add_subdirectory(tests)
endif ()

Expand Down
2 changes: 1 addition & 1 deletion include/sqlgen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "sqlgen/Flatten.hpp"
#include "sqlgen/ForeignKey.hpp"
#include "sqlgen/Iterator.hpp"
#include "sqlgen/IteratorBase.hpp"
#include "sqlgen/JSON.hpp"
#include "sqlgen/Literal.hpp"
#include "sqlgen/Pattern.hpp"
Expand Down Expand Up @@ -44,6 +43,7 @@
#include "sqlgen/read.hpp"
#include "sqlgen/rollback.hpp"
#include "sqlgen/select_from.hpp"
#include "sqlgen/sqlgen_api.hpp"
#include "sqlgen/to.hpp"
#include "sqlgen/update.hpp"
#include "sqlgen/where.hpp"
Expand Down
19 changes: 7 additions & 12 deletions include/sqlgen/Iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <memory>
#include <ranges>

#include "IteratorBase.hpp"
#include "Ref.hpp"
#include "Result.hpp"
#include "internal/batch_size.hpp"
Expand All @@ -15,23 +14,19 @@
namespace sqlgen {

/// An input_iterator that returns the underlying type.
template <class T>
template <class T, class UnderlyingIteratorT>
class Iterator {
public:
using difference_type = std::ptrdiff_t;
using value_type = Result<T>;

struct End {
bool operator==(const Iterator<T>& _it) const noexcept {
return _it == *this;
}
bool operator==(const Iterator& _it) const noexcept { return _it == *this; }

bool operator!=(const Iterator<T>& _it) const noexcept {
return _it != *this;
}
bool operator!=(const Iterator& _it) const noexcept { return _it != *this; }
};

Iterator(const Ref<IteratorBase>& _it)
Iterator(const Ref<UnderlyingIteratorT>& _it)
: current_batch_(get_next_batch(_it)), it_(_it), ix_(0) {}

~Iterator() = default;
Expand All @@ -46,7 +41,7 @@ class Iterator {

bool operator!=(const End& _end) const noexcept { return !(*this == _end); }

Iterator<T>& operator++() noexcept {
Iterator& operator++() noexcept {
++ix_;
if (ix_ >= current_batch_->size() && !it_->end()) {
current_batch_ = get_next_batch(it_);
Expand All @@ -59,7 +54,7 @@ class Iterator {

private:
static Ref<std::vector<Result<T>>> get_next_batch(
const Ref<IteratorBase>& _it) noexcept {
const Ref<UnderlyingIteratorT>& _it) noexcept {
using namespace std::ranges::views;
return _it->next(SQLGEN_BATCH_SIZE)
.transform([](auto str_vec) {
Expand All @@ -74,7 +69,7 @@ class Iterator {
Ref<std::vector<Result<T>>> current_batch_;

/// The underlying database iterator.
Ref<IteratorBase> it_;
Ref<UnderlyingIteratorT> it_;

/// The current index in the current batch.
size_t ix_;
Expand Down
29 changes: 0 additions & 29 deletions include/sqlgen/IteratorBase.hpp

This file was deleted.

1 change: 0 additions & 1 deletion include/sqlgen/Range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <memory>
#include <ranges>

#include "Iterator.hpp"
#include "Result.hpp"

namespace sqlgen {
Expand Down
2 changes: 1 addition & 1 deletion include/sqlgen/Session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <optional>
#include <vector>

#include "IteratorBase.hpp"
#include "Ref.hpp"
#include "Result.hpp"
#include "dynamic/Insert.hpp"
#include "dynamic/SelectFrom.hpp"
#include "dynamic/Statement.hpp"
Expand Down
19 changes: 14 additions & 5 deletions include/sqlgen/internal/iterator_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@

#include <type_traits>

#include "../Iterator.hpp"
#include "../Ref.hpp"
#include "../Result.hpp"

namespace sqlgen::internal {

template <class ValueType, class ConnType>
struct IteratorType;

/// Most database connectors can just use the standard iterator type, but
/// sometimes we need exception, in which case this template can be overridden.
template <class ValueType, class ConnType>
struct IteratorType {
using Type = Iterator<ValueType>;
struct IteratorType<ValueType, Ref<ConnType>> {
using Type =
typename IteratorType<ValueType, std::remove_cvref_t<ConnType>>::Type;
};

template <class ValueType, class ConnType>
struct IteratorType<ValueType, Result<ConnType>> {
using Type =
typename IteratorType<ValueType, std::remove_cvref_t<ConnType>>::Type;
};

// The specific iterator is implemented by each database in (database
// name)/Connection.hpp

template <class T, class ConnType>
using iterator_t = typename IteratorType<std::remove_cvref_t<T>,
std::remove_cvref_t<ConnType>>::Type;
Expand Down
29 changes: 17 additions & 12 deletions include/sqlgen/internal/strings/strings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@
#include <string>
#include <vector>

#include "../../sqlgen_api.hpp"

namespace sqlgen::internal::strings {

char to_lower(const char ch);
SQLGEN_API char to_lower(const char ch);

std::string to_lower(const std::string& _str);
SQLGEN_API std::string to_lower(const std::string& _str);

char to_upper(const char ch);
SQLGEN_API char to_upper(const char ch);

std::string to_upper(const std::string& _str);
SQLGEN_API std::string to_upper(const std::string& _str);

std::string join(const std::string& _delimiter,
const std::vector<std::string>& _strings);
SQLGEN_API std::string join(const std::string& _delimiter,
const std::vector<std::string>& _strings);

std::string replace_all(const std::string& _str, const std::string& _from,
const std::string& _to);
SQLGEN_API std::string replace_all(const std::string& _str,
const std::string& _from,
const std::string& _to);

std::vector<std::string> split(const std::string& _str,
const std::string& _delimiter);
SQLGEN_API std::vector<std::string> split(const std::string& _str,
const std::string& _delimiter);

std::string ltrim(const std::string& _str, const std::string& _chars = " ");
SQLGEN_API std::string ltrim(const std::string& _str,
const std::string& _chars = " ");

std::string rtrim(const std::string& _str, const std::string& _chars = " ");
SQLGEN_API std::string rtrim(const std::string& _str,
const std::string& _chars = " ");

inline std::string trim(const std::string& _str,
const std::string& _chars = " ") {
Expand Down
Loading
Loading