eis/mix_cc/sql/condition.h

49 lines
1.1 KiB
C
Raw Normal View History

/**
* @file mix_cc/sql/condition.h
* @brief
* @author Cat (null.null.null@qq.com)
* @version 0.1
* @date 2021-07-10
*
* Company: Baosight Co. Ltd.
* DO NOT COPY/USE WITHOUT PERMISSION
*
*/
#pragma once
#include <mix_cc/sql/public.h>
#include <mix_cc/sql/op/compare.h>
#include <string>
namespace mix_cc {
namespace sql {
template <typename Name, typename Comp, typename Tp>
struct condition_t {
using comp_t = Comp;
using value_type = Tp;
private:
Name col_name_;
Comp comp_;
value_type value_;
public:
constexpr condition_t(Name col, Comp comp, value_type value)
: col_name_(col), comp_(comp), value_(value) {}
~condition_t() {}
constexpr auto get_str() {
std::string value_str;
if constexpr (std::is_integral_v<value_type> ||
std::is_floating_point_v<value_type>) {
value_str = boost::str(boost::format("%1%") % value_);
} else {
value_str = boost::str(boost::format("%2%%1%%2%") % value_ % '\'');
}
return std::string(col_name_.c_str()) + " " + comp_.c_str() + " " +
value_str;
}
};
} // namespace sql
} // namespace mix_cc