mirror of
https://github.com/rbock/sqlpp11.git
synced 2026-02-17 19:58:42 -06:00
Merge branch 'feature/custom_query_return_type' into develop
This commit is contained in:
@@ -40,11 +40,23 @@ namespace sqlpp
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <typename T>
|
||||
struct unhide
|
||||
{
|
||||
using type = T;
|
||||
};
|
||||
template <typename Clause>
|
||||
struct unhide<hidden_t<Clause>>
|
||||
{
|
||||
using type = Clause;
|
||||
};
|
||||
|
||||
template <typename Db, typename... Parts>
|
||||
struct custom_parts_t
|
||||
{
|
||||
using _custom_query_t = custom_query_t<Db, Parts...>;
|
||||
using _result_type_provider = detail::get_first_if<is_return_value_t, noop, Parts...>;
|
||||
using _maybe_hidden_result_type_provider = detail::get_first_if<is_return_value_t, noop, Parts...>;
|
||||
using _result_type_provider = typename unhide<_maybe_hidden_result_type_provider>::type;
|
||||
using _result_methods_t = typename _result_type_provider::template _result_methods_t<_result_type_provider>;
|
||||
};
|
||||
}
|
||||
@@ -102,9 +114,9 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template <typename Part>
|
||||
auto with_result_type_of(Part part) -> custom_query_t<Database, Part, Parts...>
|
||||
auto with_result_type_of(Part part) -> custom_query_t<Database, hidden_t<Part>, Parts...>
|
||||
{
|
||||
return {tuple_cat(std::make_tuple(part), _parts)};
|
||||
return {tuple_cat(std::make_tuple(hidden(part)), _parts)};
|
||||
}
|
||||
|
||||
std::tuple<Parts...> _parts;
|
||||
|
||||
@@ -29,10 +29,10 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template <typename Part>
|
||||
struct hidden_t : public Part
|
||||
template <typename Clause>
|
||||
struct hidden_t : Clause
|
||||
{
|
||||
hidden_t(Part part) : Part(part)
|
||||
hidden_t(Clause clause) : Clause(clause)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -43,11 +43,11 @@ namespace sqlpp
|
||||
~hidden_t() = default;
|
||||
};
|
||||
|
||||
template <typename Context, typename Part>
|
||||
struct serializer_t<Context, hidden_t<Part>>
|
||||
template <typename Context, typename Clause>
|
||||
struct serializer_t<Context, hidden_t<Clause>>
|
||||
{
|
||||
using _serialize_check = consistent_t;
|
||||
using T = hidden_t<Part>;
|
||||
using T = hidden_t<Clause>;
|
||||
|
||||
static Context& _(const T&, Context& context)
|
||||
{
|
||||
@@ -55,8 +55,8 @@ namespace sqlpp
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Part>
|
||||
auto hidden(Part part) -> hidden_t<Part>
|
||||
template <typename Clause>
|
||||
auto hidden(Clause part) -> hidden_t<Clause>
|
||||
{
|
||||
return {part};
|
||||
}
|
||||
|
||||
@@ -23,12 +23,14 @@
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "compare.h"
|
||||
#include "Sample.h"
|
||||
#include "compare.h"
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
SQLPP_ALIAS_PROVIDER(pragma);
|
||||
|
||||
int CustomQuery(int, char* [])
|
||||
{
|
||||
const auto foo = test::TabFoo{};
|
||||
@@ -59,5 +61,10 @@ int CustomQuery(int, char* [])
|
||||
"SELECT DISTINCT tab_foo.omega FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega=tab_bar.alpha) WHERE "
|
||||
"(tab_bar.alpha>17) GROUP BY tab_foo.omega HAVING (AVG(tab_bar.alpha)>19) ORDER BY tab_foo.omega ASC ");
|
||||
|
||||
// A pragma query for sqlite
|
||||
compare(__LINE__,
|
||||
custom_query(sqlpp::verbatim("PRAGMA user_version")).with_result_type_of(select(sqlpp::value(1).as(pragma))),
|
||||
" PRAGMA user_version");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user