Skip to content

Commit

Permalink
Merge pull request #1336 from fnc12/feature/modules-support
Browse files Browse the repository at this point in the history
sqlite_orm as a C++ named module
  • Loading branch information
trueqbit authored Feb 6, 2025
2 parents d9c828d + 1d473c6 commit cfc1095
Show file tree
Hide file tree
Showing 118 changed files with 913 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
AttributeMacros: [SQLITE_ORM_CPP_LIKELY, SQLITE_ORM_CPP_UNLIKELY]
AttributeMacros: [SQLITE_ORM_CPP_LIKELY, SQLITE_ORM_CPP_UNLIKELY, SQLITE_ORM_EXPORT]
StatementMacros:
- __pragma
- _Pragma
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ set(PACKAGE_VERSION ${sqlite_orm_VERSION})
project("sqlite_orm" VERSION ${PACKAGE_VERSION})

# Handling C++ standard version to use
option(SQLITE_ORM_ENABLE_CXX_23 "Enable C++ 23" OFF)
option(SQLITE_ORM_ENABLE_CXX_20 "Enable C++ 20" OFF)
option(SQLITE_ORM_ENABLE_CXX_17 "Enable C++ 17" OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(SQLITE_ORM_ENABLE_CXX_20)
if(SQLITE_ORM_ENABLE_CXX_23)
set(CMAKE_CXX_STANDARD 23)
message(STATUS "SQLITE_ORM: Build with C++23 features")
elseif(SQLITE_ORM_ENABLE_CXX_20)
set(CMAKE_CXX_STANDARD 20)
message(STATUS "SQLITE_ORM: Build with C++20 features")
elseif(SQLITE_ORM_ENABLE_CXX_17)
Expand Down
5 changes: 5 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ configuration:
environment:
appveyor_yml_disable_ps_linux: true
matrix:
- job_name: Visual Studio 2022, x64, C++23
appveyor_build_worker_image: Visual Studio 2022
platform: x64
SQLITE_ORM_CXX_STANDARD: "-DSQLITE_ORM_ENABLE_CXX_23=ON"

- job_name: clang, C++14
appveyor_build_worker_image: Ubuntu
CC: clang
Expand Down
4 changes: 4 additions & 0 deletions dev/alias.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once

#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#include <type_traits> // std::enable_if, std::is_same
#include <utility> // std::make_index_sequence, std::move
#include <string> // std::string
#include <sstream> // std::stringstream
#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE)
#include <array>
#endif
#endif

#include "functional/cxx_type_traits_polyfill.h"
#include "functional/mpl/conditional.h"
Expand Down Expand Up @@ -185,7 +187,9 @@ namespace sqlite_orm {
inline constexpr bool is_builtin_numeric_column_alias_v<column_alias<C...>> = ((C >= '0' && C <= '9') && ...);
#endif
}
}

SQLITE_ORM_EXPORT namespace sqlite_orm {
/**
* Using a column pointer, create a column reference to an aliased table column.
*
Expand Down
8 changes: 7 additions & 1 deletion dev/alias_traits.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
#pragma once

#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#include <type_traits> // std::is_base_of, std::is_same
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
#include <concepts>
#endif
#endif

#include "functional/cxx_type_traits_polyfill.h"
#include "type_traits.h"
#include "table_reference.h"

namespace sqlite_orm {
SQLITE_ORM_EXPORT namespace sqlite_orm {

/** @short Base class for a custom table alias, column alias or expression alias.
*/
struct alias_tag {};
}

namespace sqlite_orm {
namespace internal {

template<class A>
Expand Down Expand Up @@ -65,7 +69,9 @@ namespace sqlite_orm {
template<class A>
using is_cte_moniker = polyfill::bool_constant<is_cte_moniker_v<A>>;
}
}

SQLITE_ORM_EXPORT namespace sqlite_orm {
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<class A>
concept orm_alias = std::derived_from<A, alias_tag>;
Expand Down
2 changes: 1 addition & 1 deletion dev/arg_values.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "row_extractor.h"

namespace sqlite_orm {
SQLITE_ORM_EXPORT namespace sqlite_orm {

/** @short Wrapper around a dynamically typed value object.
*/
Expand Down
4 changes: 3 additions & 1 deletion dev/arithmetic_tag.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#pragma once

#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#include <type_traits> // std::is_integral
#endif

#include "functional/mpl/conditional.h"

namespace sqlite_orm {
SQLITE_ORM_EXPORT namespace sqlite_orm {

/**
* Helper classes used by statement_binder and row_extractor.
Expand Down
4 changes: 4 additions & 0 deletions dev/ast/excluded.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#include <utility> // std::move
#endif

namespace sqlite_orm {
namespace internal {
Expand All @@ -12,7 +14,9 @@ namespace sqlite_orm {
expression_type expression;
};
}
}

SQLITE_ORM_EXPORT namespace sqlite_orm {
template<class T>
internal::excluded_t<T> excluded(T expression) {
return {std::move(expression)};
Expand Down
4 changes: 4 additions & 0 deletions dev/ast/exists.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#include <utility> // std::move
#endif

#include "../tags.h"

Expand All @@ -17,7 +19,9 @@ namespace sqlite_orm {
exists_t(expression_type expression_) : expression(std::move(expression_)) {}
};
}
}

SQLITE_ORM_EXPORT namespace sqlite_orm {
/**
* EXISTS(condition).
* Example: storage.select(columns(&Agent::code, &Agent::name, &Agent::workingArea, &Agent::comission),
Expand Down
4 changes: 4 additions & 0 deletions dev/ast/group_by.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pragma once

#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#include <tuple> // std::tuple, std::make_tuple
#include <type_traits> // std::true_type, std::false_type
#include <utility> // std::forward, std::move
#endif

#include "../functional/cxx_type_traits_polyfill.h"

Expand Down Expand Up @@ -37,7 +39,9 @@ namespace sqlite_orm {
using is_group_by = polyfill::disjunction<polyfill::is_specialization_of<T, group_by_t>,
polyfill::is_specialization_of<T, group_by_with_having>>;
}
}

SQLITE_ORM_EXPORT namespace sqlite_orm {
/**
* GROUP BY column.
* Example: storage.get_all<Employee>(group_by(&Employee::name))
Expand Down
2 changes: 2 additions & 0 deletions dev/ast/into.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ namespace sqlite_orm {
template<class T>
using is_into = polyfill::is_specialization_of<T, into_t>;
}
}

SQLITE_ORM_EXPORT namespace sqlite_orm {
template<class T>
internal::into_t<T> into() {
return {};
Expand Down
8 changes: 5 additions & 3 deletions dev/ast/match.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <utility> // std::move
#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#include <utility>
#endif

namespace sqlite_orm {
namespace internal {
Expand All @@ -11,11 +13,11 @@ namespace sqlite_orm {
using argument_type = X;

argument_type argument;

match_t(argument_type argument) : argument(std::move(argument)) {}
};
}
}

SQLITE_ORM_EXPORT namespace sqlite_orm {
template<class T, class X>
internal::match_t<T, X> match(X argument) {
return {std::move(argument)};
Expand Down
2 changes: 2 additions & 0 deletions dev/ast/rank.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ namespace sqlite_orm {
namespace internal {
struct rank_t {};
}
}

SQLITE_ORM_EXPORT namespace sqlite_orm {
inline internal::rank_t rank() {
return {};
}
Expand Down
4 changes: 4 additions & 0 deletions dev/ast/set.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#pragma once

#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#include <tuple> // std::tuple, std::tuple_size
#include <string> // std::string
#include <vector> // std::vector
#include <sstream> // std::stringstream
#include <type_traits> // std::false_type, std::true_type
#endif

#include "../tuple_helper/tuple_traits.h"
#include "../table_name_collector.h"
Expand Down Expand Up @@ -85,7 +87,9 @@ namespace sqlite_orm {
template<class C>
struct is_dynamic_set<dynamic_set_t<C>> : std::true_type {};
}
}

SQLITE_ORM_EXPORT namespace sqlite_orm {
/**
* SET keyword used in UPDATE ... SET queries.
* Args must have `assign_t` type. E.g. set(assign(&User::id, 5)) or set(c(&User::id) = 5)
Expand Down
2 changes: 2 additions & 0 deletions dev/ast/special_keywords.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace sqlite_orm {
struct current_date_t {};
struct current_timestamp_t {};
}
}

SQLITE_ORM_EXPORT namespace sqlite_orm {
inline internal::current_time_t current_time() {
return {};
}
Expand Down
4 changes: 4 additions & 0 deletions dev/ast/upsert_clause.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#pragma once

#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#if SQLITE_VERSION_NUMBER >= 3024000
#include <tuple> // std::tuple
#include <utility> // std::forward, std::move
#endif
#endif

#include "../functional/cxx_type_traits_polyfill.h"

Expand Down Expand Up @@ -51,7 +53,9 @@ namespace sqlite_orm {
template<class T>
using is_upsert_clause = polyfill::bool_constant<is_upsert_clause_v<T>>;
}
}

SQLITE_ORM_EXPORT namespace sqlite_orm {
#if SQLITE_VERSION_NUMBER >= 3024000
/**
* ON CONFLICT upsert clause builder function.
Expand Down
4 changes: 4 additions & 0 deletions dev/ast/where.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#pragma once

#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#include <type_traits> // std::false_type, std::true_type
#include <utility> // std::move
#endif

#include "../functional/cxx_type_traits_polyfill.h"
#include "../serialize_result_type.h"
Expand Down Expand Up @@ -35,7 +37,9 @@ namespace sqlite_orm {
template<class T>
struct is_where : polyfill::bool_constant<is_where_v<T>> {};
}
}

SQLITE_ORM_EXPORT namespace sqlite_orm {
/**
* WHERE clause. Use it to add WHERE conditions wherever you like.
* C is expression type. Can be any expression like: is_equal_t, is_null_t, exists_t etc
Expand Down
2 changes: 2 additions & 0 deletions dev/ast_iterator.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#pragma once

#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#include <vector> // std::vector
#include <functional> // std::reference_wrapper
#endif

#include "tuple_helper/tuple_iteration.h"
#include "type_traits.h"
Expand Down
2 changes: 2 additions & 0 deletions dev/backup.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#pragma once

#include <sqlite3.h>
#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#include <system_error> // std::system_error
#include <string> // std::string
#include <memory>
#include <utility> // std::move, std::exchange
#endif

#include "error_code.h"
#include "connection_holder.h"
Expand Down
4 changes: 3 additions & 1 deletion dev/carray.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Hence we make it only available for compilers supporting inline variables.
*/

#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#if SQLITE_VERSION_NUMBER >= 3020000
#ifdef SQLITE_ORM_INLINE_VARIABLES_SUPPORTED
#include <utility> // std::move
Expand All @@ -14,12 +15,13 @@
#endif
#endif
#endif
#endif

#include "pointer_value.h"

#if SQLITE_VERSION_NUMBER >= 3020000
#ifdef SQLITE_ORM_INLINE_VARIABLES_SUPPORTED
namespace sqlite_orm {
SQLITE_ORM_EXPORT namespace sqlite_orm {

#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
inline constexpr orm_pointer_type auto carray_pointer_tag = "carray"_pointer_type;
Expand Down
2 changes: 2 additions & 0 deletions dev/column_expression.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pragma once

#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#include <type_traits> // std::enable_if, std::is_same, std::decay, std::is_arithmetic
#include <tuple> // std::tuple
#include <functional> // std::reference_wrapper
#endif

#include "functional/cxx_type_traits_polyfill.h"
#include "tuple_helper/tuple_transformer.h"
Expand Down
2 changes: 2 additions & 0 deletions dev/column_names_getter.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#pragma once

#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#include <type_traits> // std::is_base_of
#include <string> // std::string
#include <vector> // std::vector
#include <functional> // std::reference_wrapper
#include <system_error>
#include <utility> // std::move
#endif

#include "tuple_helper/tuple_traits.h"
#include "tuple_helper/tuple_iteration.h"
Expand Down
4 changes: 4 additions & 0 deletions dev/column_pointer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#pragma once

#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#include <type_traits> // std::enable_if, std::is_convertible
#include <utility> // std::move
#endif

#include "functional/cxx_core_features.h"
#include "functional/cxx_type_traits_polyfill.h"
Expand Down Expand Up @@ -40,7 +42,9 @@ namespace sqlite_orm {
struct alias_holder;
#endif
}
}

SQLITE_ORM_EXPORT namespace sqlite_orm {
/**
* Explicitly refer to a column, used in contexts
* where the automatic object mapping deduction needs to be overridden.
Expand Down
Loading

0 comments on commit cfc1095

Please sign in to comment.