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
5 changes: 2 additions & 3 deletions dev/ast/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace sqlite_orm {
template<class L, class R>
void push_back(assign_t<L, R> assign) {
auto newContext = this->context;
newContext.skip_table_name = true;
newContext.omit_table_name = true;
// note: we are only interested in the table name on the left-hand side of the assignment operator expression
iterate_ast(assign.lhs, this->collector);
std::stringstream ss;
Expand Down Expand Up @@ -108,7 +108,6 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
*/
template<class S>
internal::dynamic_set_t<internal::serializer_context<typename S::db_objects_type>> dynamic_set(const S& storage) {
internal::serializer_context_builder<S> builder(storage);
return builder();
return {obtain_db_objects(storage)};
}
}
4 changes: 2 additions & 2 deletions dev/column_names_getter.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace sqlite_orm {
if (definedOrder) {
auto& table = pick_table<mapped_type_proxy_t<T>>(context.db_objects);
collectedExpressions.reserve(collectedExpressions.size() + table.template count_of<is_column>());
table.for_each_column([qualified = !context.skip_table_name,
table.for_each_column([qualified = !context.omit_table_name,
&tableName = table.name,
&collectedExpressions](const column_identifier& column) {
if constexpr (is_alias<T>::value) {
Expand All @@ -50,7 +50,7 @@ namespace sqlite_orm {
collectedExpressions.reserve(collectedExpressions.size() + 1);
if constexpr (is_alias<T>::value) {
collectedExpressions.push_back(quote_identifier(alias_extractor<T>::extract()) + ".*");
} else if (!context.skip_table_name) {
} else if (!context.omit_table_name) {
const basic_table& table = pick_table<mapped_type_proxy_t<T>>(context.db_objects);
collectedExpressions.push_back(quote_identifier(table.name) + ".*");
} else {
Expand Down
5 changes: 2 additions & 3 deletions dev/conditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ namespace sqlite_orm {
template<class O>
void push_back(order_by_t<O> orderBy) {
auto newContext = this->context;
newContext.skip_table_name = false;
newContext.omit_table_name = false;
auto columnName = serialize(orderBy._expression, newContext);
this->entries.emplace_back(std::move(columnName), std::move(orderBy._collate_argument), orderBy._order);
}
Expand Down Expand Up @@ -1149,8 +1149,7 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
template<class S>
internal::dynamic_order_by_t<internal::serializer_context<typename S::db_objects_type>>
dynamic_order_by(const S& storage) {
internal::serializer_context_builder<S> builder(storage);
return builder();
return {obtain_db_objects(storage)};
}

/**
Expand Down
4 changes: 2 additions & 2 deletions dev/cte_column_names_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace sqlite_orm {
SQLITE_ORM_STATIC_CALLOP std::vector<std::string>
operator()(const expression_type& t, const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
auto newContext = context;
newContext.skip_table_name = true;
newContext.omit_table_name = true;
std::string columnName = serialize(t, newContext);
if (columnName.empty()) {
throw std::system_error{orm_error_code::column_not_found};
Expand Down Expand Up @@ -137,7 +137,7 @@ namespace sqlite_orm {
std::vector<std::string> columnNames;
columnNames.reserve(size_t(cols.count));
auto newContext = context;
newContext.skip_table_name = true;
newContext.omit_table_name = true;
iterate_tuple(cols.columns, [&columnNames, &newContext](auto& m) {
using value_type = polyfill::remove_cvref_t<decltype(m)>;

Expand Down
6 changes: 3 additions & 3 deletions dev/implementations/storage_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ namespace sqlite_orm {
namespace internal {
template<class... DBO>
template<class Table, satisfies<is_table, Table>>
sync_schema_result storage_t<DBO...>::sync_table([[maybe_unused]] const Table& table,
[[maybe_unused]] sqlite3* db,
[[maybe_unused]] bool preserve) {
sync_schema_result storage_t<DBO...>::sync_dbo([[maybe_unused]] const Table& table,
[[maybe_unused]] sqlite3* db,
[[maybe_unused]] bool preserve) {
if constexpr (
#ifdef SQLITE_ENABLE_DBSTAT_VTAB
std::is_same<object_type_t<Table>, dbstat>::value ||
Expand Down
2 changes: 1 addition & 1 deletion dev/mapped_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace sqlite_orm {

auto& dbObjects = obtain_db_objects(this->storage);
context_t context{dbObjects};
context.skip_table_name = false;
context.omit_table_name = false;
context.replace_bindable_with_question = true;

const std::string sql = serialize(this->expression, context);
Expand Down
2 changes: 1 addition & 1 deletion dev/order_by_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace sqlite_orm {
const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
std::stringstream ss;
auto newContext = context;
newContext.skip_table_name = false;
newContext.omit_table_name = false;

ss << serialize(orderBy._expression, newContext);
seralize_collate(ss, orderBy);
Expand Down
42 changes: 42 additions & 0 deletions dev/prepared_statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,48 @@ namespace sqlite_orm {

template<class T>
using is_insert_constraint = std::is_same<T, insert_constraint>;

/**
* Specialize if a type is a DML statement expression.
*/
template<class T, class SFINAE = void>
inline constexpr bool is_raw_dml_expression_v = false;

template<class T>
using is_raw_dml_expression = polyfill::bool_constant<is_raw_dml_expression_v<T>>;

template<class DML>
inline constexpr bool is_raw_dml_expression_v<
DML,
std::enable_if_t<
polyfill::
disjunction_v<is_insert_raw<DML>, is_replace_raw<DML>, is_update_all<DML>, is_remove_all<DML>>>> =
true;

template<class With>
inline constexpr bool is_raw_dml_expression_v<
With,
std::enable_if_t<polyfill::conjunction_v<is_with_clause<With>,
polyfill::disjunction<is_insert_raw<expression_type_t<With>>,
is_replace_raw<expression_type_t<With>>,
is_update_all<expression_type_t<With>>,
is_remove_all<expression_type_t<With>>>>>> =
true;

/*
* Access the main select expression of a with clause or the passed in select expression.
*/
template<class DML, satisfies<is_raw_dml_expression, DML> = true>
constexpr decltype(auto) access_main_dml(const DML& dml) {
if constexpr (is_with_clause_v<DML>) {
return (dml.expression);
} else {
return dml;
}
}

template<class DML>
using main_dml_t = polyfill::remove_cvref_t<decltype(access_main_dml(std::declval<DML>()))>;
}
}

Expand Down
2 changes: 1 addition & 1 deletion dev/result_set_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace sqlite_orm::internal {
using context_t = serializer_context<ExprDBOs>;

context_t context{exprDBOs};
context.skip_table_name = false;
context.omit_table_name = false;
context.replace_bindable_with_question = true;

const std::string sql = serialize(this->expression, context);
Expand Down
3 changes: 3 additions & 0 deletions dev/schema/column.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ namespace sqlite_orm {
template<class T>
using is_column = polyfill::bool_constant<is_column_v<T>>;

template<class Elements>
using col_index_sequence_of = filter_tuple_sequence_t<Elements, is_column>;

template<class Elements, class F>
using col_index_sequence_with_field_type =
filter_tuple_sequence_t<Elements,
Expand Down
6 changes: 2 additions & 4 deletions dev/schema/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ namespace sqlite_orm {
*/
template<class L>
void for_each_column(L&& lambda) const {
using col_index_sequence = filter_tuple_sequence_t<elements_type, is_column>;
iterate_tuple(this->elements, col_index_sequence{}, lambda);
iterate_tuple(this->elements, col_index_sequence_of<elements_type>{}, lambda);
}

/**
Expand Down Expand Up @@ -379,8 +378,7 @@ namespace sqlite_orm {
*/
template<class L>
void for_each_column(L&& lambda) const {
using col_index_sequence = filter_tuple_sequence_t<columns_type, is_column>;
iterate_tuple(this->columns, col_index_sequence{}, lambda);
iterate_tuple(this->columns, col_index_sequence_of<columns_type>{}, lambda);
}

template<class M, satisfies<std::is_member_pointer, M> = true>
Expand Down
41 changes: 41 additions & 0 deletions dev/select_constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,17 @@ namespace sqlite_orm {
}
}
};

template<class T>
inline constexpr bool is_with_clause_v = polyfill::is_specialization_of<T, with_t>::value;
#else
template<class T>
inline constexpr bool is_with_clause_v = false;
#endif

template<class T>
using is_with_clause = polyfill::bool_constant<is_with_clause_v<T>>;

template<class T>
struct asterisk_t {
using type = T;
Expand Down Expand Up @@ -388,6 +397,38 @@ namespace sqlite_orm {
}
};

/**
* Specialize if a type is a select statement expression.
*/
template<class T, class SFINAE = void>
inline constexpr bool is_select_expression_v = false;

template<class T>
using is_select_expression = polyfill::bool_constant<is_select_expression_v<T>>;

template<class Select>
inline constexpr bool is_select_expression_v<Select, std::enable_if_t<is_select_v<Select>>> = true;

template<class With>
inline constexpr bool is_select_expression_v<
With,
std::enable_if_t<polyfill::conjunction_v<is_with_clause<With>, is_select<expression_type_t<With>>>>> = true;

/*
* Access the main select expression of a with clause or the passed in select expression.
*/
template<class Select, satisfies<is_select_expression, Select> = true>
constexpr decltype(auto) access_main_select(const Select& select) {
if constexpr (is_with_clause_v<Select>) {
return (select.expression);
} else {
return select;
}
}

template<class Select>
using main_select_t = polyfill::remove_cvref_t<decltype(access_main_select(std::declval<Select>()))>;

template<class T, std::enable_if_t<!is_rowset_deduplicator_v<T>, bool> = true>
const T& access_column_expression(const T& expression) {
return expression;
Expand Down
18 changes: 2 additions & 16 deletions dev/serializer_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace sqlite_orm {

struct serializer_context_base {
bool replace_bindable_with_question = false;
bool skip_table_name = true;
bool omit_table_name = true;
bool use_parentheses = true;
bool fts5_columns = false;
bool omit_column_type = false;
};

template<class DBOs>
Expand All @@ -19,20 +19,6 @@ namespace sqlite_orm {

serializer_context(const db_objects_type& dbObjects) : db_objects{dbObjects} {}
};

template<class S>
struct serializer_context_builder {
using storage_type = S;
using db_objects_type = typename storage_type::db_objects_type;

serializer_context_builder(const storage_type& storage_) : storage{storage_} {}

serializer_context<db_objects_type> operator()() const {
return {obtain_db_objects(this->storage)};
}

const storage_type& storage;
};
}

}
2 changes: 1 addition & 1 deletion dev/serializing_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ namespace sqlite_orm {
ss << ' ' << serialize(constraint, context);
});
// add implicit null constraint
if (!context.fts5_columns) {
if (!context.omit_column_type) {
constexpr bool hasExplicitNullableConstraint =
mpl::invoke_t<mpl::disjunction<check_if_has_type<null_t>, check_if_has_type<not_null_t>>,
constraints_tuple>::value;
Expand Down
Loading