0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Added interpret support for remove()

This commit is contained in:
rbock 2014-01-15 08:24:42 +01:00
parent 54fa55e6a5
commit 54d45e97ae
4 changed files with 44 additions and 13 deletions

View File

@ -57,6 +57,9 @@ namespace sqlpp
static_assert(is_noop<Using>::value or is_using_t<Using>::value, "invalid 'Using' argument");
static_assert(is_noop<Where>::value or is_where_t<Where>::value, "invalid 'Where' argument");
// FIXME: We might want to have everywhere() or all() to indicate that everything is to be removed, same with update and select
template<typename UsingT>
using set_using_t = remove_t<Database, Table, UsingT, Where>;
template<typename WhereT>
@ -134,17 +137,6 @@ namespace sqlpp
return *this;
}
template<typename Db>
const remove_t& serialize(std::ostream& os, Db& db) const
{
os << "DELETE FROM ";
_table.serialize(os, db);
_using.serialize(os, db);
_where.serialize(os, db);
return *this;
}
static constexpr size_t _get_static_no_of_parameters()
{
return _parameter_list_t::size::value;
@ -174,6 +166,21 @@ namespace sqlpp
Where _where;
};
template<typename Context, typename Database, typename Table, typename Using, typename Where>
struct interpreter_t<Context, remove_t<Database, Table, Using, Where>>
{
using T = remove_t<Database, Table, Using, Where>;
static Context& _(const T& t, Context& context)
{
context << "DELETE FROM ";
interpret(t._table, context);
interpret(t._using, context);
interpret(t._where, context);
return context;
}
};
template<typename Table>
constexpr remove_t<void, typename std::decay<Table>::type> remove_from(Table&& table)
{

View File

@ -138,7 +138,7 @@ namespace sqlpp
static Context& _(const T& t, Context& context)
{
context << "table";
context << T::_name_t::_get_name(); // FIXME: need a special rule for pseudo tables
return context;
}
};

View File

@ -79,6 +79,25 @@ namespace sqlpp
detail::serializable_list<Database> _dynamic_tables;
};
template<typename Context, typename Database, typename... Table>
struct interpreter_t<Context, using_t<Database, Table...>>
{
using T = using_t<Database, Table...>;
static Context& _(const T& t, Context& context)
{
if (sizeof...(Table) == 0 and t._dynamic_tables.empty())
return context;
context << " USING ";
interpret_tuple(t._tables, ',', context);
if (sizeof...(Table) and not t._dynamic_tables.empty())
context << ',';
interpret_serializable_list(t._dynamic_tables, ',', context);
return context;
}
};
}
#endif

View File

@ -25,9 +25,10 @@
#include "TabSample.h"
#include "MockDb.h"
#include <sqlpp11/select.h>
#include <sqlpp11/insert.h>
#include <sqlpp11/select.h>
#include <sqlpp11/update.h>
#include <sqlpp11/remove.h>
#include <sqlpp11/functions.h>
#include <iostream>
@ -70,5 +71,9 @@ int main()
interpret(update(t).set(t.gamma = true), printer).flush();
interpret(update(t).set(t.gamma = true).where(t.beta.in("kaesekuchen", "cheesecake")), printer).flush();
interpret(remove_from(t), printer).flush();
interpret(remove_from(t).where(t.alpha == sqlpp::tvin(0)), printer).flush();
interpret(remove_from(t).using_(t).where(t.alpha == sqlpp::tvin(0)), printer).flush();
return 0;
}