Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/simplified_expression_object_typ…
Browse files Browse the repository at this point in the history
…e' into CTEs
  • Loading branch information
trueqbit committed Dec 25, 2023
2 parents b2c77f2 + 6e465f1 commit 5ef6d4e
Show file tree
Hide file tree
Showing 26 changed files with 619 additions and 595 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SQLite ORM light header only library for modern C++. Please read the license pre
* **No raw string queries**
* **Intuitive syntax**
* **Comfortable interface - one code line per single query**
* **Built with modern C++14 features (no macros and external scripts)**
* **Built with modern C++14/C++17/C++20 features (no macros and external scripts)**
* **CRUD support**
* **Pure select query support**
* **Prepared statements support**
Expand Down
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ for:
install:
- |-
cd C:\Tools\vcpkg
git fetch --tags && git checkout 2023.11.20
git fetch --tags && git checkout 2023.12.12
cd %APPVEYOR_BUILD_FOLDER%
C:\Tools\vcpkg\bootstrap-vcpkg.bat -disableMetrics
C:\Tools\vcpkg\vcpkg integrate install
Expand Down Expand Up @@ -140,7 +140,7 @@ for:
install:
- |-
pushd $HOME/vcpkg
git fetch --tags && git checkout 2023.11.20
git fetch --tags && git checkout 2023.12.12
popd
$HOME/vcpkg/bootstrap-vcpkg.sh -disableMetrics
$HOME/vcpkg/vcpkg integrate install --overlay-triplets=vcpkg/triplets
Expand Down Expand Up @@ -168,7 +168,7 @@ for:
# using custom vcpkg triplets for building and linking dynamic dependent libraries
install:
- |-
git clone --depth 1 --branch 2023.11.20 https://github.com/microsoft/vcpkg.git $HOME/vcpkg
git clone --depth 1 --branch 2023.12.12 https://github.com/microsoft/vcpkg.git $HOME/vcpkg
$HOME/vcpkg/bootstrap-vcpkg.sh -disableMetrics
$HOME/vcpkg/vcpkg integrate install --overlay-triplets=vcpkg/triplets
vcpkg install sqlite3[core,dbstat,math,json1,fts5] catch2 --overlay-triplets=vcpkg/triplets
Expand Down
16 changes: 3 additions & 13 deletions dev/ast_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,12 @@ namespace sqlite_orm {
};

template<class T>
struct ast_iterator<T, match_if<is_binary_condition, T>> {
struct ast_iterator<T,
std::enable_if_t<polyfill::disjunction_v<is_binary_condition<T>, is_binary_operator<T>>>> {
using node_type = T;

template<class L>
void operator()(const node_type& binaryCondition, L& lambda) const {
iterate_ast(binaryCondition.l, lambda);
iterate_ast(binaryCondition.r, lambda);
}
};

template<class T>
struct ast_iterator<T, match_if<is_binary_operator, T>> {
using node_type = T;

template<class C>
void operator()(const node_type& node, C& lambda) const {
void operator()(const node_type& node, L& lambda) const {
iterate_ast(node.lhs, lambda);
iterate_ast(node.rhs, lambda);
}
Expand Down
18 changes: 9 additions & 9 deletions dev/column_names_getter.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ namespace sqlite_orm {
if(columnExpression.empty()) {
throw std::system_error{orm_error_code::column_not_found};
}
collectedExpressions.reserve(collectedExpressions.size() + 1);
collectedExpressions.push_back(std::move(columnExpression));
return collectedExpressions;
this->collectedExpressions.reserve(this->collectedExpressions.size() + 1);
this->collectedExpressions.push_back(std::move(columnExpression));
return this->collectedExpressions;
}

template<class T, class Ctx>
Expand All @@ -83,27 +83,27 @@ namespace sqlite_orm {

template<class T, class Ctx>
std::vector<std::string>& operator()(const asterisk_t<T>& expression, const Ctx& context) {
return collect_table_column_names<T>(collectedExpressions, expression.defined_order, context);
return collect_table_column_names<T>(this->collectedExpressions, expression.defined_order, context);
}

template<class T, class Ctx>
std::vector<std::string>& operator()(const object_t<T>& expression, const Ctx& context) {
return collect_table_column_names<T>(collectedExpressions, expression.defined_order, context);
return collect_table_column_names<T>(this->collectedExpressions, expression.defined_order, context);
}

template<class... Args, class Ctx>
std::vector<std::string>& operator()(const columns_t<Args...>& cols, const Ctx& context) {
collectedExpressions.reserve(collectedExpressions.size() + cols.count);
this->collectedExpressions.reserve(this->collectedExpressions.size() + cols.count);
iterate_tuple(cols.columns, [this, &context](auto& colExpr) {
(*this)(colExpr, context);
});
// note: `capacity() > size()` can occur in case `asterisk_t<>` does spell out the columns in defined order
if(mpl::invoke_t<check_if_tuple_has_template<asterisk_t>,
typename columns_t<Args...>::columns_type>::value &&
collectedExpressions.capacity() > collectedExpressions.size()) {
collectedExpressions.shrink_to_fit();
this->collectedExpressions.capacity() > this->collectedExpressions.size()) {
this->collectedExpressions.shrink_to_fit();
}
return collectedExpressions;
return this->collectedExpressions;
}

std::vector<std::string> collectedExpressions;
Expand Down
27 changes: 16 additions & 11 deletions dev/conditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "constraints.h"
#include "optional_container.h"
#include "serializer_context.h"
#include "serialize_result_type.h"
#include "tags.h"
#include "alias_traits.h"
#include "expression.h"
Expand Down Expand Up @@ -127,12 +128,12 @@ namespace sqlite_orm {
using right_type = R;
using result_type = Res;

left_type l;
right_type r;
left_type lhs;
right_type rhs;

binary_condition() = default;

binary_condition(left_type l_, right_type r_) : l(std::move(l_)), r(std::move(r_)) {}
binary_condition(left_type l_, right_type r_) : lhs(std::move(l_)), rhs(std::move(r_)) {}
};

template<class T>
Expand All @@ -142,7 +143,7 @@ namespace sqlite_orm {
using is_binary_condition = polyfill::bool_constant<is_binary_condition_v<T>>;

struct and_condition_string {
operator std::string() const {
serialize_result_type serialize() const {
return "AND";
}
};
Expand All @@ -158,7 +159,7 @@ namespace sqlite_orm {
};

struct or_condition_string {
operator std::string() const {
serialize_result_type serialize() const {
return "OR";
}
};
Expand All @@ -174,7 +175,7 @@ namespace sqlite_orm {
};

struct is_equal_string {
operator std::string() const {
serialize_result_type serialize() const {
return "=";
}
};
Expand Down Expand Up @@ -223,7 +224,7 @@ namespace sqlite_orm {
};

struct is_not_equal_string {
operator std::string() const {
serialize_result_type serialize() const {
return "!=";
}
};
Expand Down Expand Up @@ -251,7 +252,7 @@ namespace sqlite_orm {
};

struct greater_than_string {
operator std::string() const {
serialize_result_type serialize() const {
return ">";
}
};
Expand Down Expand Up @@ -279,7 +280,7 @@ namespace sqlite_orm {
};

struct greater_or_equal_string {
operator std::string() const {
serialize_result_type serialize() const {
return ">=";
}
};
Expand Down Expand Up @@ -307,7 +308,7 @@ namespace sqlite_orm {
};

struct less_than_string {
operator std::string() const {
serialize_result_type serialize() const {
return "<";
}
};
Expand Down Expand Up @@ -335,7 +336,7 @@ namespace sqlite_orm {
};

struct less_or_equal_string {
operator std::string() const {
serialize_result_type serialize() const {
return "<=";
}
};
Expand Down Expand Up @@ -898,6 +899,8 @@ namespace sqlite_orm {
class R,
std::enable_if_t<polyfill::disjunction_v<std::is_base_of<arithmetic_t, L>,
std::is_base_of<arithmetic_t, R>,
std::is_base_of<condition_t, L>,
std::is_base_of<condition_t, R>,
is_operator_argument<L>,
is_operator_argument<R>>,
bool> = true>
Expand All @@ -909,6 +912,8 @@ namespace sqlite_orm {
class R,
std::enable_if_t<polyfill::disjunction_v<std::is_base_of<arithmetic_t, L>,
std::is_base_of<arithmetic_t, R>,
std::is_base_of<condition_t, L>,
std::is_base_of<condition_t, R>,
is_operator_argument<L>,
is_operator_argument<R>>,
bool> = true>
Expand Down
52 changes: 15 additions & 37 deletions dev/expression_object_type.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include <type_traits> // std::decay
#include <type_traits> // std::decay, std::remove_reference
#include <functional> // std::reference_wrapper

#include "type_traits.h"
#include "prepared_statement.h"

namespace sqlite_orm {
Expand All @@ -13,58 +14,35 @@ namespace sqlite_orm {
struct expression_object_type;

template<class T>
struct expression_object_type<update_t<T>> : std::decay<T> {};
using expression_object_type_t = typename expression_object_type<T>::type;

template<class T>
struct expression_object_type<update_t<std::reference_wrapper<T>>> : std::decay<T> {};
template<typename S>
using statement_object_type_t = expression_object_type_t<expression_type_t<std::remove_reference_t<S>>>;

template<class T>
struct expression_object_type<replace_t<T>> : std::decay<T> {};
struct expression_object_type<update_t<T>, void> : value_unref_type<T> {};

template<class T>
struct expression_object_type<replace_t<std::reference_wrapper<T>>> : std::decay<T> {};

template<class It, class L, class O>
struct expression_object_type<replace_range_t<It, L, O>> {
using type = typename replace_range_t<It, L, O>::object_type;
};
struct expression_object_type<replace_t<T>, void> : value_unref_type<T> {};

template<class It, class L, class O>
struct expression_object_type<replace_range_t<std::reference_wrapper<It>, L, O>> {
using type = typename replace_range_t<std::reference_wrapper<It>, L, O>::object_type;
template<class T>
struct expression_object_type<T, match_if<is_replace_range, T>> {
using type = object_type_t<T>;
};

template<class T, class... Ids>
struct expression_object_type<remove_t<T, Ids...>> {
using type = T;
};

template<class T, class... Ids>
struct expression_object_type<remove_t<std::reference_wrapper<T>, Ids...>> {
using type = T;
};
struct expression_object_type<remove_t<T, Ids...>, void> : value_unref_type<T> {};

template<class T>
struct expression_object_type<insert_t<T>> : std::decay<T> {};
struct expression_object_type<insert_t<T>, void> : value_unref_type<T> {};

template<class T>
struct expression_object_type<insert_t<std::reference_wrapper<T>>> : std::decay<T> {};

template<class It, class L, class O>
struct expression_object_type<insert_range_t<It, L, O>> {
using type = typename insert_range_t<It, L, O>::object_type;
};

template<class It, class L, class O>
struct expression_object_type<insert_range_t<std::reference_wrapper<It>, L, O>> {
using type = typename insert_range_t<std::reference_wrapper<It>, L, O>::object_type;
struct expression_object_type<T, match_if<is_insert_range, T>> {
using type = object_type_t<T>;
};

template<class T, class... Cols>
struct expression_object_type<insert_explicit<T, Cols...>> : std::decay<T> {};

template<class T, class... Cols>
struct expression_object_type<insert_explicit<std::reference_wrapper<T>, Cols...>> : std::decay<T> {};
struct expression_object_type<insert_explicit<T, Cols...>, void> : value_unref_type<T> {};

template<class T>
struct get_ref_t {
Expand Down
16 changes: 9 additions & 7 deletions dev/get_prepared_statement.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#pragma once

#include <type_traits> // std::is_same, std::decay, std::remove_reference
#include <type_traits> // std::is_same, std::remove_reference, std::remove_cvref
#include <tuple> // std::get

#include "functional/cxx_universal.h" // ::size_t
#include "functional/cxx_type_traits_polyfill.h"
#include "functional/static_magic.h"
#include "type_traits.h"
#include "prepared_statement.h"
#include "ast_iterator.h"
#include "node_tuple.h"
Expand Down Expand Up @@ -124,14 +126,14 @@ namespace sqlite_orm {

template<int N, class T>
const auto& get(const internal::prepared_statement_t<T>& statement) {
using statement_type = std::decay_t<decltype(statement)>;
using expression_type = typename statement_type::expression_type;
using statement_type = polyfill::remove_cvref_t<decltype(statement)>;
using expression_type = internal::expression_type_t<statement_type>;
using node_tuple = internal::node_tuple_t<expression_type>;
using bind_tuple = internal::bindable_filter_t<node_tuple>;
using result_type = std::tuple_element_t<static_cast<size_t>(N), bind_tuple>;
const result_type* result = nullptr;
internal::iterate_ast(statement.expression, [&result, index = -1](auto& node) mutable {
using node_type = std::decay_t<decltype(node)>;
using node_type = polyfill::remove_cvref_t<decltype(node)>;
if(internal::is_bindable_v<node_type>) {
++index;
}
Expand All @@ -149,15 +151,15 @@ namespace sqlite_orm {

template<int N, class T>
auto& get(internal::prepared_statement_t<T>& statement) {
using statement_type = std::decay_t<decltype(statement)>;
using expression_type = typename statement_type::expression_type;
using statement_type = std::remove_reference_t<decltype(statement)>;
using expression_type = internal::expression_type_t<statement_type>;
using node_tuple = internal::node_tuple_t<expression_type>;
using bind_tuple = internal::bindable_filter_t<node_tuple>;
using result_type = std::tuple_element_t<static_cast<size_t>(N), bind_tuple>;
result_type* result = nullptr;

internal::iterate_ast(statement.expression, [&result, index = -1](auto& node) mutable {
using node_type = std::decay_t<decltype(node)>;
using node_type = polyfill::remove_cvref_t<decltype(node)>;
if(internal::is_bindable_v<node_type>) {
++index;
}
Expand Down
Loading

0 comments on commit 5ef6d4e

Please sign in to comment.