From db1b43432075fa028fba73992b8adb9770bd54a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dr=2E=20Patrick=20Urbanke=20=28=E5=8A=89=E8=87=AA=E6=88=90?= =?UTF-8?q?=29?= Date: Wed, 16 Jul 2025 23:35:18 +0200 Subject: [PATCH] Added more rigorous checks to the select_from query (#28) --- include/sqlgen/select_from.hpp | 13 +++++++++++++ include/sqlgen/transpilation/columns_t.hpp | 3 ++- include/sqlgen/transpilation/table_tuple_t.hpp | 3 +++ include/sqlgen/transpilation/to_sets.hpp | 18 +++++++++++------- include/sqlgen/transpilation/underlying_t.hpp | 2 +- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/include/sqlgen/select_from.hpp b/include/sqlgen/select_from.hpp index 1a26f21..996508a 100644 --- a/include/sqlgen/select_from.hpp +++ b/include/sqlgen/select_from.hpp @@ -133,6 +133,17 @@ struct SelectFrom { const SelectFrom& _s, const transpilation::Join& _join) { + static_assert(std::is_same_v, + "You cannot call where(...) before a join."); + static_assert(std::is_same_v, + "You cannot call group_by(...) before a join."); + static_assert(std::is_same_v, + "You cannot call order_by(...) before a join."); + static_assert(std::is_same_v, + "You cannot call limit(...) before a join."); + static_assert(std::is_same_v, + "You cannot call to<...> before a join."); + if constexpr (std::is_same_v) { using NewJoinsType = rfl::Tuple< transpilation::Join>; @@ -161,6 +172,8 @@ struct SelectFrom { static_assert(std::is_same_v, "You cannot call where(...) twice (but you can apply more " "than one condition by combining them with && or ||)."); + static_assert(std::is_same_v, + "You cannot call group_by(...) before where(...)."); static_assert(std::is_same_v, "You cannot call order_by(...) before where(...)."); static_assert(std::is_same_v, diff --git a/include/sqlgen/transpilation/columns_t.hpp b/include/sqlgen/transpilation/columns_t.hpp index c06eebd..092c65e 100644 --- a/include/sqlgen/transpilation/columns_t.hpp +++ b/include/sqlgen/transpilation/columns_t.hpp @@ -21,7 +21,8 @@ struct Columns { template auto make_columns() { - static_assert(all_columns_exist(), "All columns must exist."); + static_assert(all_columns_exist(), + "At least one column referenced in your query does not exist."); return Columns{}; } diff --git a/include/sqlgen/transpilation/table_tuple_t.hpp b/include/sqlgen/transpilation/table_tuple_t.hpp index 46d5464..d5992c0 100644 --- a/include/sqlgen/transpilation/table_tuple_t.hpp +++ b/include/sqlgen/transpilation/table_tuple_t.hpp @@ -25,6 +25,9 @@ struct TableTupleType> { std::pair, AliasType>, std::pair, typename JoinTypes::Alias>...>; + static_assert( + !rfl::define_literal_t::has_duplicates(), + "Your SELECT FROM query cannot contain duplicate aliases."); }; template diff --git a/include/sqlgen/transpilation/to_sets.hpp b/include/sqlgen/transpilation/to_sets.hpp index f05fb73..3a071f8 100644 --- a/include/sqlgen/transpilation/to_sets.hpp +++ b/include/sqlgen/transpilation/to_sets.hpp @@ -27,8 +27,9 @@ struct ToSet; template struct ToSet, ToType>> { - static_assert(all_columns_exist>(), - "All columns must exist."); + static_assert( + all_columns_exist>(), + "At least one column referenced in your SET query does not exist."); static_assert(std::is_convertible_v>, underlying_t>>, "Must be convertible."); @@ -44,14 +45,17 @@ struct ToSet, ToType>> { template struct ToSet, transpilation::Col<_name2>>> { - static_assert(all_columns_exist>(), - "All columns must exist."); - static_assert(all_columns_exist>(), - "All columns must exist."); + static_assert( + all_columns_exist>(), + "At least one column referenced in your SET query does not exist."); + static_assert( + all_columns_exist>(), + "At least one column referenced in your SET query does not exist."); static_assert( std::is_convertible_v>, underlying_t>>, - "Must be convertible."); + "A column referenced in your SET query is not convertible to the column " + "it is being assigned to."); dynamic::Update::Set operator()(const auto& _set) const { return dynamic::Update::Set{ diff --git a/include/sqlgen/transpilation/underlying_t.hpp b/include/sqlgen/transpilation/underlying_t.hpp index 910a9bb..9c26de8 100644 --- a/include/sqlgen/transpilation/underlying_t.hpp +++ b/include/sqlgen/transpilation/underlying_t.hpp @@ -34,7 +34,7 @@ template struct Underlying> { static_assert(all_columns_exist>(), - "All columns must exist."); + "At least one column referenced in your query does not exist."); using Type = remove_reflection_t< rfl::field_type_t<_name, get_table_t, TableTupleType>>>; };