Skip to content

Commit

Permalink
table refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
fnc12 committed Oct 2, 2023
1 parent 0e571da commit 38fd3f1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 54 deletions.
10 changes: 5 additions & 5 deletions dev/statement_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ namespace sqlite_orm {
ss << "UPDATE " << streaming_identifier(table.name) << " SET ";
table.template for_each_column_excluding<mpl::disjunction_fn<is_primary_key, is_generated_always>>(
[&table, &ss, &context, &object = get_ref(statement.object), first = true](auto& column) mutable {
if(table.exists_in_composite_primary_key(column)) {
if(exists_in_composite_primary_key(table, column)) {
return;
}

Expand All @@ -1069,7 +1069,7 @@ namespace sqlite_orm {
ss << " WHERE ";
table.for_each_column(
[&table, &context, &ss, &object = get_ref(statement.object), first = true](auto& column) mutable {
if(!column.template is<is_primary_key>() && !table.exists_in_composite_primary_key(column)) {
if(!column.template is<is_primary_key>() && !exists_in_composite_primary_key(table, column)) {
return;
}

Expand Down Expand Up @@ -1175,7 +1175,7 @@ namespace sqlite_orm {
mpl::conjunction<mpl::not_<mpl::always<is_without_rowid>>,
mpl::disjunction_fn<is_primary_key, is_generated_always>>>(
[&table, &columnNames](auto& column) {
if(table.exists_in_composite_primary_key(column)) {
if(exists_in_composite_primary_key(table, column)) {
return;
}

Expand All @@ -1197,7 +1197,7 @@ namespace sqlite_orm {
mpl::conjunction<mpl::not_<mpl::always<is_without_rowid>>,
mpl::disjunction_fn<is_primary_key, is_generated_always>>{},
[&table](auto& column) {
return table.exists_in_composite_primary_key(column);
return exists_in_composite_primary_key(table, column);
},
context,
get_ref(statement.object))
Expand Down Expand Up @@ -1337,7 +1337,7 @@ namespace sqlite_orm {
mpl::conjunction<mpl::not_<mpl::always<is_without_rowid>>,
mpl::disjunction_fn<is_primary_key, is_generated_always>>>(
[&table, &columnNames](auto& column) {
if(table.exists_in_composite_primary_key(column)) {
if(exists_in_composite_primary_key(table, column)) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions dev/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ namespace sqlite_orm {
mpl::conjunction<mpl::not_<mpl::always<is_without_rowid>>,
mpl::disjunction_fn<is_primary_key, is_generated_always>>>(
call_as_template_base<column_field>([&table, &bindValue, &object](auto& column) {
if(!table.exists_in_composite_primary_key(column)) {
if(!exists_in_composite_primary_key(table, column)) {
bindValue(polyfill::invoke(column.member_pointer, object));
}
}));
Expand Down Expand Up @@ -1262,12 +1262,12 @@ namespace sqlite_orm {
auto& object = get_object(statement.expression);
table.template for_each_column_excluding<mpl::disjunction_fn<is_primary_key, is_generated_always>>(
call_as_template_base<column_field>([&table, &bindValue, &object](auto& column) {
if(!table.exists_in_composite_primary_key(column)) {
if(!exists_in_composite_primary_key(table, column)) {
bindValue(polyfill::invoke(column.member_pointer, object));
}
}));
table.for_each_column([&table, &bindValue, &object](auto& column) {
if(column.template is<is_primary_key>() || table.exists_in_composite_primary_key(column)) {
if(column.template is<is_primary_key>() || exists_in_composite_primary_key(table, column)) {
bindValue(polyfill::invoke(column.member_pointer, object));
}
});
Expand Down
38 changes: 19 additions & 19 deletions dev/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,6 @@ namespace sqlite_orm {
return result;
}

template<class G, class S>
bool exists_in_composite_primary_key(const column_field<G, S>& column) const {
bool res = false;
this->for_each_primary_key([&column, &res](auto& primaryKey) {
using colrefs_tuple = decltype(primaryKey.columns);
using same_type_index_sequence =
filter_tuple_sequence_t<colrefs_tuple,
check_if_is_type<member_field_type_t<G>>::template fn,
member_field_type_t>;
iterate_tuple(primaryKey.columns, same_type_index_sequence{}, [&res, &column](auto& memberPointer) {
if(compare_any(memberPointer, column.member_pointer) ||
compare_any(memberPointer, column.setter)) {
res = true;
}
});
});
return res;
}

/**
* Call passed lambda with all defined primary keys.
*/
Expand Down Expand Up @@ -284,6 +265,25 @@ namespace sqlite_orm {

template<class O, bool W, class... Cs>
struct is_table<table_t<O, W, Cs...>> : std::true_type {};

template<class O, bool WithoutRowId, class... Cs, class G, class S>
bool exists_in_composite_primary_key(const table_t<O, WithoutRowId, Cs...>& table,
const column_field<G, S>& column) {
bool res = false;
table.for_each_primary_key([&column, &res](auto& primaryKey) {
using colrefs_tuple = decltype(primaryKey.columns);
using same_type_index_sequence =
filter_tuple_sequence_t<colrefs_tuple,
check_if_is_type<member_field_type_t<G>>::template fn,
member_field_type_t>;
iterate_tuple(primaryKey.columns, same_type_index_sequence{}, [&res, &column](auto& memberPointer) {
if(compare_any(memberPointer, column.member_pointer) || compare_any(memberPointer, column.setter)) {
res = true;
}
});
});
return res;
}
}

/**
Expand Down
54 changes: 27 additions & 27 deletions include/sqlite_orm/sqlite_orm.h
Original file line number Diff line number Diff line change
Expand Up @@ -9810,25 +9810,6 @@ namespace sqlite_orm {
return result;
}

template<class G, class S>
bool exists_in_composite_primary_key(const column_field<G, S>& column) const {
bool res = false;
this->for_each_primary_key([&column, &res](auto& primaryKey) {
using colrefs_tuple = decltype(primaryKey.columns);
using same_type_index_sequence =
filter_tuple_sequence_t<colrefs_tuple,
check_if_is_type<member_field_type_t<G>>::template fn,
member_field_type_t>;
iterate_tuple(primaryKey.columns, same_type_index_sequence{}, [&res, &column](auto& memberPointer) {
if(compare_any(memberPointer, column.member_pointer) ||
compare_any(memberPointer, column.setter)) {
res = true;
}
});
});
return res;
}

/**
* Call passed lambda with all defined primary keys.
*/
Expand Down Expand Up @@ -9978,6 +9959,25 @@ namespace sqlite_orm {

template<class O, bool W, class... Cs>
struct is_table<table_t<O, W, Cs...>> : std::true_type {};

template<class O, bool WithoutRowId, class... Cs, class G, class S>
bool exists_in_composite_primary_key(const table_t<O, WithoutRowId, Cs...>& table,
const column_field<G, S>& column) {
bool res = false;
table.for_each_primary_key([&column, &res](auto& primaryKey) {
using colrefs_tuple = decltype(primaryKey.columns);
using same_type_index_sequence =
filter_tuple_sequence_t<colrefs_tuple,
check_if_is_type<member_field_type_t<G>>::template fn,
member_field_type_t>;
iterate_tuple(primaryKey.columns, same_type_index_sequence{}, [&res, &column](auto& memberPointer) {
if(compare_any(memberPointer, column.member_pointer) || compare_any(memberPointer, column.setter)) {
res = true;
}
});
});
return res;
}
}

/**
Expand Down Expand Up @@ -16449,7 +16449,7 @@ namespace sqlite_orm {
ss << "UPDATE " << streaming_identifier(table.name) << " SET ";
table.template for_each_column_excluding<mpl::disjunction_fn<is_primary_key, is_generated_always>>(
[&table, &ss, &context, &object = get_ref(statement.object), first = true](auto& column) mutable {
if(table.exists_in_composite_primary_key(column)) {
if(exists_in_composite_primary_key(table, column)) {
return;
}

Expand All @@ -16460,7 +16460,7 @@ namespace sqlite_orm {
ss << " WHERE ";
table.for_each_column(
[&table, &context, &ss, &object = get_ref(statement.object), first = true](auto& column) mutable {
if(!column.template is<is_primary_key>() && !table.exists_in_composite_primary_key(column)) {
if(!column.template is<is_primary_key>() && !exists_in_composite_primary_key(table, column)) {
return;
}

Expand Down Expand Up @@ -16566,7 +16566,7 @@ namespace sqlite_orm {
mpl::conjunction<mpl::not_<mpl::always<is_without_rowid>>,
mpl::disjunction_fn<is_primary_key, is_generated_always>>>(
[&table, &columnNames](auto& column) {
if(table.exists_in_composite_primary_key(column)) {
if(exists_in_composite_primary_key(table, column)) {
return;
}

Expand All @@ -16588,7 +16588,7 @@ namespace sqlite_orm {
mpl::conjunction<mpl::not_<mpl::always<is_without_rowid>>,
mpl::disjunction_fn<is_primary_key, is_generated_always>>{},
[&table](auto& column) {
return table.exists_in_composite_primary_key(column);
return exists_in_composite_primary_key(table, column);
},
context,
get_ref(statement.object))
Expand Down Expand Up @@ -16728,7 +16728,7 @@ namespace sqlite_orm {
mpl::conjunction<mpl::not_<mpl::always<is_without_rowid>>,
mpl::disjunction_fn<is_primary_key, is_generated_always>>>(
[&table, &columnNames](auto& column) {
if(table.exists_in_composite_primary_key(column)) {
if(exists_in_composite_primary_key(table, column)) {
return;
}

Expand Down Expand Up @@ -18591,7 +18591,7 @@ namespace sqlite_orm {
mpl::conjunction<mpl::not_<mpl::always<is_without_rowid>>,
mpl::disjunction_fn<is_primary_key, is_generated_always>>>(
call_as_template_base<column_field>([&table, &bindValue, &object](auto& column) {
if(!table.exists_in_composite_primary_key(column)) {
if(!exists_in_composite_primary_key(table, column)) {
bindValue(polyfill::invoke(column.member_pointer, object));
}
}));
Expand Down Expand Up @@ -18643,12 +18643,12 @@ namespace sqlite_orm {
auto& object = get_object(statement.expression);
table.template for_each_column_excluding<mpl::disjunction_fn<is_primary_key, is_generated_always>>(
call_as_template_base<column_field>([&table, &bindValue, &object](auto& column) {
if(!table.exists_in_composite_primary_key(column)) {
if(!exists_in_composite_primary_key(table, column)) {
bindValue(polyfill::invoke(column.member_pointer, object));
}
}));
table.for_each_column([&table, &bindValue, &object](auto& column) {
if(column.template is<is_primary_key>() || table.exists_in_composite_primary_key(column)) {
if(column.template is<is_primary_key>() || exists_in_composite_primary_key(table, column)) {
bindValue(polyfill::invoke(column.member_pointer, object));
}
});
Expand Down

0 comments on commit 38fd3f1

Please sign in to comment.