eis/mix_cc/sql/where.h

43 lines
1.2 KiB
C
Raw Normal View History

/**
* @file mix_cc/sql/where.h
* @brief
* @author Cat (null.null.null@qq.com)
* @version 0.1
* @date 2021-09-17
*
* Copyright: Baosight Co. Ltd.
* DO NOT COPY/USE WITHOUT PERMISSION
*
*/
#pragma once
#include <mix_cc/sql/public.h>
#include <mix_cc/sql/condition.h>
#include <mix_cc/sql/statement.h>
#include <string>
#include <algorithm>
namespace mix_cc {
namespace sql {
template <typename PrevStatement, typename... Conditions>
struct where_t : public prev_statement_t<PrevStatement>, public statement_t {
static constexpr auto s_text = op::cmd_t::where;
constexpr explicit where_t(PrevStatement prev_st, Conditions... conditions)
: prev_statement_t<PrevStatement>(prev_st), conditions_(conditions...) {}
constexpr auto get_command() {
auto sel_str_c = " "_s + s_text + " "_s;
auto conditions_str =
hana::transform(conditions_, [](auto col) { return col.get_str(); });
auto r_str = hana::fold_left(conditions_str, [](auto cond1, auto cond2) {
return cond1 + " AND " + cond2;
});
return std::string(sel_str_c.c_str()) + r_str;
}
hana::tuple<Conditions...> conditions_;
};
} // namespace sql
} // namespace mix_cc