Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions include/sqlgen/select_from.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ struct SelectFrom {
const SelectFrom& _s,
const transpilation::Join<TableOrQueryType, ConditionType, _alias>&
_join) {
static_assert(std::is_same_v<WhereType, Nothing>,
"You cannot call where(...) before a join.");
static_assert(std::is_same_v<GroupByType, Nothing>,
"You cannot call group_by(...) before a join.");
static_assert(std::is_same_v<OrderByType, Nothing>,
"You cannot call order_by(...) before a join.");
static_assert(std::is_same_v<LimitType, Nothing>,
"You cannot call limit(...) before a join.");
static_assert(std::is_same_v<ToType, Nothing>,
"You cannot call to<...> before a join.");

if constexpr (std::is_same_v<JoinsType, Nothing>) {
using NewJoinsType = rfl::Tuple<
transpilation::Join<TableOrQueryType, ConditionType, _alias>>;
Expand Down Expand Up @@ -161,6 +172,8 @@ struct SelectFrom {
static_assert(std::is_same_v<WhereType, Nothing>,
"You cannot call where(...) twice (but you can apply more "
"than one condition by combining them with && or ||).");
static_assert(std::is_same_v<GroupByType, Nothing>,
"You cannot call group_by(...) before where(...).");
static_assert(std::is_same_v<OrderByType, Nothing>,
"You cannot call order_by(...) before where(...).");
static_assert(std::is_same_v<LimitType, Nothing>,
Expand Down
3 changes: 2 additions & 1 deletion include/sqlgen/transpilation/columns_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ struct Columns {

template <class T, class... ColTypes>
auto make_columns() {
static_assert(all_columns_exist<T, ColTypes...>(), "All columns must exist.");
static_assert(all_columns_exist<T, ColTypes...>(),
"At least one column referenced in your query does not exist.");
return Columns<ColTypes...>{};
}

Expand Down
3 changes: 3 additions & 0 deletions include/sqlgen/transpilation/table_tuple_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ struct TableTupleType<StructType, AliasType, rfl::Tuple<JoinTypes...>> {
std::pair<extract_table_t<StructType>, AliasType>,
std::pair<extract_table_t<typename JoinTypes::TableOrQueryType>,
typename JoinTypes::Alias>...>;
static_assert(
!rfl::define_literal_t<typename JoinTypes::Alias...>::has_duplicates(),
"Your SELECT FROM query cannot contain duplicate aliases.");
};

template <class StructType, class AliasType, class JoinsType>
Expand Down
18 changes: 11 additions & 7 deletions include/sqlgen/transpilation/to_sets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ struct ToSet;

template <class T, rfl::internal::StringLiteral _name, class ToType>
struct ToSet<T, Set<transpilation::Col<_name>, ToType>> {
static_assert(all_columns_exist<T, transpilation::Col<_name>>(),
"All columns must exist.");
static_assert(
all_columns_exist<T, transpilation::Col<_name>>(),
"At least one column referenced in your SET query does not exist.");
static_assert(std::is_convertible_v<underlying_t<T, Col<_name>>,
underlying_t<T, Value<ToType>>>,
"Must be convertible.");
Expand All @@ -44,14 +45,17 @@ struct ToSet<T, Set<transpilation::Col<_name>, ToType>> {
template <class T, rfl::internal::StringLiteral _name1,
rfl::internal::StringLiteral _name2>
struct ToSet<T, Set<transpilation::Col<_name1>, transpilation::Col<_name2>>> {
static_assert(all_columns_exist<T, transpilation::Col<_name1>>(),
"All columns must exist.");
static_assert(all_columns_exist<T, transpilation::Col<_name2>>(),
"All columns must exist.");
static_assert(
all_columns_exist<T, transpilation::Col<_name1>>(),
"At least one column referenced in your SET query does not exist.");
static_assert(
all_columns_exist<T, transpilation::Col<_name2>>(),
"At least one column referenced in your SET query does not exist.");
static_assert(
std::is_convertible_v<underlying_t<T, transpilation::Col<_name2>>,
underlying_t<T, transpilation::Col<_name1>>>,
"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{
Expand Down
2 changes: 1 addition & 1 deletion include/sqlgen/transpilation/underlying_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ template <class TableTupleType, rfl::internal::StringLiteral _name,
rfl::internal::StringLiteral _alias>
struct Underlying<TableTupleType, Col<_name, _alias>> {
static_assert(all_columns_exist<TableTupleType, Col<_name, _alias>>(),
"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<Literal<_alias>, TableTupleType>>>;
};
Expand Down
Loading